Pulling A Username From A Dict
-
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 attributeuser
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.
-
It should be either
t['user']['screen_name']
ort.get('user').get('screen_name')
.
-
t.get('user').get('screen_name')
did the trick. Thanks.