gpt4 book ai didi

python - 访问 python 字典

转载 作者:太空狗 更新时间:2023-10-30 00:33:47 24 4
gpt4 key购买 nike

我正在编写代码来搜索 Twitter 的关键词并将它们存储在 Python 字典中:

        base_url = 'http://search.twitter.com/search.json?rpp=100&q=4sq.com/'
query = '7bOHRP'
url_string = base_url + query
logging.info("url string = " + url_string)
json_text = fetch(url_string)
json_response = simplejson.loads(json_text.content)
result = json_response['results']
print "Contents"
print result

生成的字典是:

Contents[{
u 'iso_language_code': u 'en',
u 'text': u "I'm at Cafe en Seine (40 Dawson Street, Dublin) w/ 2 others. http://4sq.com/7bOHRP",
u 'created_at': u 'Wed, 06 Oct 2010 23:37:02 +0000',
u 'profile_image_url': u 'http://a1.twimg.com/profile_images/573130785/twitterProfilePhoto_normal.jpg',
u 'source': u '<a href="http://foursquare.com" rel="nofollow">foursquare</a>',
u 'place': {
u 'type': u 'neighborhood',
u 'id': u '898cf727ca504e96',
u 'full_name': u 'Mansion House B, Dublin'
},
u 'from_user': u 'pkerssemakers',
u 'from_user_id': 60241195,
u 'to_user_id': None,
u 'geo': None,
u 'id': 26597357992,
u 'metadata': {
u 'result_type': u 'recent'
}
}]
Status: 200 OK
Content - Type: text / html;charset = utf - 8
Cache - Control: no - cache
Expires: Fri, 01 Jan 1990 00: 00: 00 GMT
Content - Length: 0

如何访问“from_user”以及键和值之前的“u”是什么?

最佳答案

result[0][u'from_user']

u 前缀表示它是一个 unicode而不是 str

关于python - 访问 python 字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3933478/

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