syntaxError: 'continue' not properly in loop

前端 未结 2 1324
执念已碎
执念已碎 2021-02-13 01:00

I have been struggling with this error for a while now and there seems to be different opinions regarding why the interpreter complains about the \'continue\'. So I would like t

2条回答
  •  长发绾君心
    2021-02-13 01:12

    continue is only allowed within a for or while loop. You can easily restructure your function to loop until a valid request.

    def writeHandlesToFile():
        while True:
            with open("dataFile.txt","w") as f:
                try:
                    lst = tweepy.Cursor(tweepy.api.followers,screen_name='someHandle',).items(100000)
                    print "cursor executed"
                    for item in lst:
                        f.write(item.screen_name+"\n")
                    break
                except tweepy.error.TweepError as e:
                    print "In the except method"
                    print e
                    time.sleep(3600)
    

提交回复
热议问题