我是python的新手。我需要從一個基本上是json格式的tweet流的文本文件中訪問字段。該文本文件如下所示:從文本文件訪問字段
{u'favorited': False, u'entities': {u'user_mentions': [{u'indices': [76, 84], u'id': 10228272, u'id_str': u'10228272', u'name': u'YouTube', u'screen_name': u'YouTube'}], u'hashtags': [], u'urls': [{u'indices': [52, 71], u'url': u'http://t.co/iQYW4d3', u'expanded_url': u'http://www.youtube.com/watch?v=-HGfFyqJMrk', u'display_url': u'youtube.com/watch?v=-HGfFy\u2026'}]}, u'contributors': None, u'truncated': False, u'text': u'Long Live Egypt.....A MUST watch..... Freeeeedom... http://t.co/iQYW4d3 via @youtube', u'created_at': u'Sun Feb 06 17:18:21 +0000 2011', u'retweeted': False, u'in_reply_to_status_id_str': None, u'coordinates': None, u'id': 34299873733902336L, u'source': u'<a href="http://twitter.com/tweetbutton" rel="nofollow">Tweet Button</a>', u'in_reply_to_status_id': None, u'id_str': u'34299873733902336', u'in_reply_to_screen_name': None, u'user': {u'follow_request_sent': None, u'profile_use_background_image': True, u'id': 191652149, u'verified': False, u'profile_sidebar_fill_color': u'c9c9c9', u'profile_text_color': u'1c1f23', u'followers_count': 43, u'protected': False, u'location': u'Damascus - Syria', u'profile_background_color': u'07090b', u'listed_count': 3, u'utc_offset': 7200, u'statuses_count': 113, u'description': u'In heaven, all the interesting people are missing ', u'friends_count': 149, u'profile_link_color': u'c34242', u'profile_image_url': u'http://a3.twimg.com/profile_images/1125299662/Untitled_normal.jpg', u'notifications': None, u'show_all_inline_media': False, u'geo_enabled': False, u'id_str': u'191652149', u'profile_background_image_url': u'http://a0.twimg.com/profile_background_images/150071579/x07823fa2328f1ff92c4d900c44bc34d.jpg', u'screen_name': u'NourZoukar', u'lang': u'en', u'following': None, u'profile_background_tile': True, u'favourites_count': 0, u'name': u'M.Nour Zoukar', u'url': u'http://www.kawngroup.com', u'created_at': u'Fri Sep 17 00:19:26 +0000 2010', u'contributors_enabled': False, u'time_zone': u'Jerusalem', u'profile_sidebar_border_color': u'bfbfbf', u'is_translator': False}, u'place': None, u'retweet_count': 0, u'geo': None, u'in_reply_to_user_id_str': None, u'in_reply_to_user_id': None}
我希望我的輸出顯示在這種情況下'NourZoukar'的屏幕名稱。
其實它看起來像它應該是'鳴叫[「用戶」] [「SCREEN_NAME」]',但肯定的。 – Johnsyweb
我從文本文件複製了上面給出的文本,當我嘗試使用json.loads()加載文件時,它給出TypeError:期望的字符串或緩衝區。 – Annie
你需要顯示你的實際代碼。你如何準確加載它? –