Home > OS >  Unable to access the key of a dictionary in python
Unable to access the key of a dictionary in python

Time:05-18

I'm trying to access a key of a dictionary here

{'application_id': '467377486141980682',
 'attachments': [],
 'author': {'avatar': '25cb9058944599f9f1ba15279f9e4a8f',
            'bot': True,
            'discriminator': '0000',
            'id': '964810500611375104',
            'username': 'Sparky99'},
 'channel_id': '790967460039491644',
 'components': [],
 'content': '73561',
 'edited_timestamp': None,
 'embeds': [],
 'flags': 0,
 'id': '976330290698006528',
 'mention_everyone': False,
 'mention_roles': [],
 'mentions': [],
 'pinned': False,
 'timestamp': '2022-05-18T03:48:00.642000 00:00',
 'tts': False,
 'type': 0,
 'webhook_id': '964810500611375104'}

I can access all these except the username.

When I run dic.get("username") , it returns none like if doesn't exists but all other elements are accessible to me using dic.get()

Note: Tell me if I need to add some more info to the question.

CodePudding user response:

username isn't a key in that dictionary. There's a key called author whose value is a dictionary and in there, you can find username.

  • Related