我希望每当有人提到我('@ name')时它会打印到控制台的东西,把它写到文件中,所以它不会打印相同的提及两次,并等到下一次提到出现 .
Function 在课堂内,如果重要的话 . myMentions = tweepy.Cursor(api.mentions_timeline).items()
def check_if_won(self, myMentions):
openfile = open('lastid.txt', 'r')
readfromfile = openfile.read()
for mention in myMentions:
if str(mention.id) not in readfromfile:
try:
writetofile = open('lastid.txt', 'a')
writetofile.write(str(mention.id))
writetofile.close()
print(mention.text)
print("$$$$$$$$$$$$ JACKPOT $$$$$$$$$$$$")
print('\n')
except Exception:
pass
else:
pass
我哪里做错了?