Wheatley
Wheatley

Reputation: 35

Stop script and return to beginning

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.

Upvotes: 1

Views: 40

Answers (2)

Wheatley
Wheatley

Reputation: 35

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

Upvotes: 0

user19950573
user19950573

Reputation:

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

Upvotes: 1

Related Questions