我一直在为这个错误苦苦挣扎,对于解释器为什么抱怨“continue”存在不同的看法。因此,我想在下面提供有误的代码。
import tweepy
import time
def writeHandlesToFile():
file = open("dataFile.txt","w")
try:
list = tweepy.Cursor(tweepy.api.followers,screen_name='someHandle',).items(100000)
print "cursor executed"
for item in list:
file.write(item.screen_name+"\n")
except tweepy.error.TweepError as e:
print "In the except method"
print e
time.sleep(3600)
continue
我在最后使用continue的原因是,我希望程序在sleep之后从离开的地方重新开始执行,以维护程序状态。我需要sleep来遵守Twitter API的速率限制,该API每小时只允许你发送一定数量的请求。
如果有人发现了我的错误或提供了不使用continue语句的替代实现,请告诉我。
顺便说一下,我并没有像另一篇文章中建议的那样混合使用制表符和空格。
非常感谢你的帮助。
break
用于跳出循环。它是 try 块中执行的最后一行代码。 - Tim