Forum Archive

Pulling A Username From A Dict

techteej

So I know this is pretty basic, but haven't found anything to really help me and I've exhausted my options to either get an error or a None return.

As you can see here, the attribute screen_name is inside of the attribute user which could easily be called by using ['user']['screen_name'] except in my instance below:

# coding: utf-8
import twitter
all_accounts = twitter.get_all_accounts()
if len(all_accounts) >= 1:
    account = all_accounts[0]
    tweets = twitter.get_home_timeline(account)
    for t in tweets:
        print t.get('text')
        print t.get(['user']['screen_name'])
        print '=' * 40
else:
    print 'You don\'t have any Twitter accounts (or haven\'t given permission to access them).'

Any help is appreciated.

omz

It should be either t['user']['screen_name'] or t.get('user').get('screen_name').

techteej

t.get('user').get('screen_name') did the trick. Thanks.