gpt4 book ai didi

python - 从文本文件访问字段

转载 作者:行者123 更新时间:2023-11-28 22:04:28 26 4
gpt4 key购买 nike

我是 python 的新手。我需要访问文本文件中的字段,该文件基本上是 json 格式的推文流。文本文件如下所示:

{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”。

最佳答案

我非常怀疑这是原始 JSON 文本格式。在我看来,这就像使用 json.loads() 将其加载到 Python 中后的输出。

鉴于它已经是字典,您只需执行 data['screen_name']

关于python - 从文本文件访问字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7105194/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com