我要确保每次有人提到我(“ @name”)时,它都会在控制台中打印出一些内容,将其写入文件中,这样它就不会打印两次相同的内容,直到下一次提及出现。
功能在类中,如果有的话。 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
我哪里出错了?