创建循环?

2024-04-26 18:22:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个python新手,但我想知道如何创建一个循环,以便下面的代码可以在多个twitter id上运行,而不仅仅是“4330165050859037888”?你知道吗

到目前为止,我已经:

import tweepy


consumer_key=""
consumer_secret=""
access_key = ""
access_secret = "" 


auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)

def get_retweet_count(tweet_id):
    tweet = api.get_status(tweet_id)
    return tweet.retweet_count

print get_retweet_count( '433016508592037888')

任何帮助都会很好。你知道吗


Tags: key代码authapiidgetsecretaccess
1条回答
网友
1楼 · 发布于 2024-04-26 18:22:40

如果您的id在列表中:

例如:id_list = [id, id, id, id, id]# imagine those are id numbers :)

然后你可以这样做:

for id in id_list:
    print get_retweet_count(id)

有关for循环和python循环的一般信息,请单击herehere(codeacademy, python tutorials)并单击google;)

相关问题 更多 >