syntaxError: ‘continue’ not properly in loop

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)

Why do I get a `NameError` (or `UnboundLocalError`) from using a named exception after the `except` block?

The try statement explicitly limits the scope of the bound exception, to prevent circular references causing it to leak. When an exception has been assigned using as target, it is cleared at the end of the except clause. […] This means the exception must be assigned to a different name to be able to refer … Read more

Why doesn’t this Python keyboard interrupt work? (in PyCharm)

I know this is an old question, but I ran into the same problem and think there’s an easier solution: In PyCharm go to “Run”https://stackoverflow.com/”Edit Configurations” and check “Emulate terminal in output console”. PyCharm now accepts keyboard interrupts (make sure the console is focused). Tested on: PyCharm 2019.1 (Community Edition)

How to properly ignore exceptions

try: doSomething() except: pass or try: doSomething() except Exception: pass The difference is that the first one will also catch KeyboardInterrupt, SystemExit and stuff like that, which are derived directly from exceptions.BaseException, not exceptions.Exception. See documentation for details: try statement exceptions