myDict = results(results)
print("Subscribers: " + myDict['items'][0]['statistics']['subscriberCount'])
I am trying to store results as a variable to then use to only display a certain part of the output.
If I write
results_print(results)
it prints correctly but I can't store it as a variable for some reason.
This is the content of the results:
{'pageInfo': {'resultsPerPage': 1, 'totalResults': 1}, 'items': [{'snippet': {'publishedAt': '2013-10-20T10:33:50.000Z', 'country': 'SE', 'localized': {'description': 'Trap Town, the best trap music out there.\n\nSubmissions: traptownsubmit@gmail.com', 'title': 'Trap Town'}, 'customUrl': 'traptownmusic', 'title': 'Trap Town', 'description': 'Trap Town, the best trap music out there.\n\nSubmissions: traptownsubmit@gmail.com', 'thumbnails': {'default': {'url': 'https://yt3.ggpht.com/-4E1iRrrd_c8/AAAAAAAAAAI/AAAAAAAAAAA/cJeykUlKy8s/s88-c-k-no-mo-rj-c0xffffff/photo.jpg'}, 'medium': {'url': 'https://yt3.ggpht.com/-4E1iRrrd_c8/AAAAAAAAAAI/AAAAAAAAAAA/cJeykUlKy8s/s240-c-k-no-mo-rj-c0xffffff/photo.jpg'}, 'high': {'url': 'https://yt3.ggpht.com/-4E1iRrrd_c8/AAAAAAAAAAI/AAAAAAAAAAA/cJeykUlKy8s/s240-c-k-no-mo-rj-c0xffffff/photo.jpg'}}}, 'statistics': {'videoCount': '354', 'commentCount': '0', 'hiddenSubscriberCount': False, 'viewCount': '1417504', 'subscriberCount': '12178'}, 'kind': 'youtube#channel', 'id': 'UCipITl9sF0qOhCyx9CyoPGA', 'etag': '"m2yskBQFythfE4irbTIeOgYYfBU/dy7xO_v59s1GVGj_ZJRXB_3rico"', 'contentDetails': {'relatedPlaylists': {'watchHistory': 'HL', 'uploads': 'UUipITl9sF0qOhCyx9CyoPGA', 'favorites': 'FLipITl9sF0qOhCyx9CyoPGA', 'watchLater': 'WL', 'likes': 'LLipITl9sF0qOhCyx9CyoPGA'}}}], 'kind': 'youtube#channelListResponse', 'etag': '"m2yskBQFythfE4irbTIeOgYYfBU/p-3fTLLWdWeBZO-Q-vqxfEbNIhw"'}
This is the function?
def channels_list_by_id(service, **kwargs):
kwargs = remove_empty_kwargs(**kwargs) # See full sample for function
results = service.channels().list(
**kwargs
).execute()
def print_results(results):
print(results)