Python: How to tell the for loop to continue from a function?
问题 Sometimes I need the following pattern within a for loop. At times more than once in the same loop: try: var = 'attempt to do something that may fail on a number of levels' except Exception, e: log(e) continue Now I don't see a nice way to wrap this in a function as it can not return continue : def attempt(this): try: return this except Exception, e: log(e) # 1. continue # <-- syntax error: continue not properly in loop or # 2. return continue # <-- invalid syntax # 3. return False # <-- this