omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Pulling A Username From A Dict

    Pythonista
    twitter
    2
    3
    2690
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • techteej
      techteej last edited by 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.

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

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

        1 Reply Last reply Reply Quote 0
        • techteej
          techteej last edited by

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors