【发布时间】:2022-01-21 08:02:09
【问题描述】:
我的 Python 函数正在打印我的变量 current_tweet_id 的值,但是当我返回相同的变量时,在另一个函数中调用它时,我在终端中得到一个 None 类型。有谁知道为什么会这样?
def get_mentions():
# Collect Mentions
tweets = client.get_users_mentions(id=id, tweet_fields=['context_annotations','created_at','geo'])
for tweet in tweets.data:
current_tweet_id = str(tweet.id)
# Read CSV
lines = open("C:\\Users\\User\\Documents\\more_jpeg\\mentions.csv", "r").read()
# Check CSV for Tweet ID
with open("C:\\Users\\User\\Documents\\more_jpeg\\mentions.csv", "a+") as fp:
if current_tweet_id in lines:
break
else:
fp.write(current_tweet_id + "\n")
print(current_tweet_id)
return current_tweet_id
【问题讨论】:
标签: python python-3.x python-2.7