Home > other >  Stop script and return to beginning
Stop script and return to beginning

Time:09-30

I have a python script that is using

while:

try:

except:

I am wondering how to stop it running (not exit script) and then return to the beginning.

CodePudding user response:

Just wrap it with another loop, and add some conditions to avoid infinite loop.

is_done = False
while is_done:
  while your_condition:
    try:
      # Your task
      is_done = True
      break
    except Exception as e:
      print(e)
      break

CodePudding user response:

I think I have this now. when using except, just call the main function again.

  • Related