python - 创建循环?

标签 python loops tweepy

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

到目前为止我已经:

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')

任何帮助都会很棒。

最佳答案

如果您的 ID 在列表中:

例如:id_list = [id, id, id, id, id] # 想象这些是 id 号码:)

那么你可以这样做:

for id in id_list:
    print get_retweet_count(id)

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

关于python - 创建循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21699677/

相关文章:

python - tweepy流到sqlite数据库-语法错误

python - 如何在 tensorflow 1.15 中正确传递权重和偏差?

python - Flask 如何将@login_required 重定向到特定路由?

javascript - 将相邻重复值分组到数组中的最佳方法

java - 使用 rnd 值防止无限循环

python - 如何修复 tweepy 中的编码?

python 2.7 : 'Ramón' == u'Ramón'

python - 将自定义测试套件运行器与 pytest-django 一起使用

python - 使用 numpy 数组优化 python 函数

python - tweepy:找到转推的原作者