-1

I want to automate the python to re-run the code when it returns error, is it possible and how can I do it?

I have a script and each time that returns an error I have to run it again. The error does not interfere in the process, so it can't be a problem re-run.

3
  • this got nothing with python but with the way you run it. Commented Nov 7, 2022 at 19:50
  • 1
    Why not use a try - except block to catch the error, and handle it that way? Commented Nov 7, 2022 at 19:54
  • It's seems a good idea. Commented Nov 7, 2022 at 19:56

1 Answer 1

1

When you face an error, typically, the program will halt. That's why there are error handlers in place to not let that happen.

Look at some already answered examples here

So, lets say you want the user to input integer values and it shouldn't halt, so you could use a loop and break it when the entered value is an integer (there's no error thrown)

...
while True:
  try:
    i = int(input("Integer: "))
    break
  except:
    print("Error")
...

You get the idea.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.