Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中存储twiiter api中的屏幕名称?_Python_Twitter - Fatal编程技术网

如何在python中存储twiiter api中的屏幕名称?

如何在python中存储twiiter api中的屏幕名称?,python,twitter,Python,Twitter,我试图从twitterapi中存储screen_名称,以便将其存储在一个文件中,但是它是用户属性的一部分。如果我将屏幕名称存储到字典中,有人能建议我应该在python脚本中编写什么代码吗? tweet的一个例子是 u‘用户’:{u'name':u'Chris D',u'lang':u'ru',u'profile_background_tile':False,u'favorites_count':0,u'screen_name':u'cdraven87',u'notifications':None

我试图从twitterapi中存储screen_名称,以便将其存储在一个文件中,但是它是用户属性的一部分。如果我将屏幕名称存储到字典中,有人能建议我应该在python脚本中编写什么代码吗? tweet的一个例子是

u‘用户’:{u'name':u'Chris D',u'lang':u'ru',u'profile_background_tile':False,u'favorites_count':0,u'screen_name':u'cdraven87',u'notifications':None,u'created_at':u'Mon 11:33:57+0000 2014',u'contributors_enabled_':False,u'time_zone':None,u'protected:False,u'profile':False,u'isu翻译:False},u'geo':无,u'in'u-reply\u-to\u-user\u-id\u-str':无,u'mably\u-sensitive':False,u'lang':u'en',u'created\u-at':u'Mon Nov 10 11:55:00+0000 2014',u'filter\u level':u'medium',u'in'in'reply\u-to\u-status\u-id\u-str':无,u'place:None}

我的代码是:

        dictionary['screen_name'] = tweet['screen_name']
        dictionary['favourites'] = tweet['favourites_count']
        dictionary['followers'] = tweet['followers_count']

要访问用户密钥下的词典,可以链接它们:

dictionary['screen_name'] = tweet['user']['screen_name']

顺便说一句,这些用户名和屏幕名不是属性,它们是字典中的键。

我不明白重点。你想要实现什么?您将tweet的一些键/值对复制到另一个字典。是否要将词典保存到文件中?如果是这样,请使用pickle。我想将屏幕名称、收藏夹计数和追随者计数保存到字典中。然而,这些是用户的子属性。描述tweet的所有属性都存储在twitterAPI的变量tweet中。问题是将子属性与用户属性分开…然后首先使用tweet['user']['screen_name']获取用户的dict。ictionary={}dictionary['tweet']=tweet['text']dictionary['id']=tweet['id']dictionary['created_at']=tweet['created_at']json_data=json.dumpsdictionary saveFile=open'tweetBitcoin.json','a'a=append saveFile.writejson_data saveFile.write'\n'saveFile.close忘记pickle。问题是我无法保存screen_name属性,因为它是user的子属性…谢谢,现在才看到。干杯,朋友,我来试一试