Ask coding questions

← Back to all posts
Restart script from within itself [Python]
OskarSrslett (0)

Can you completly restart a script within a python file with a function?

Comments
hotnewtop
Coder100 (18123)

sure

step 1:
create a .replit file:

run = "while [ true ]; do python main.py ; done"

step 2:
to 'restart', do this:

import sys

sys.exit(1)
robowolf (549)

You could put the script in the function and then at then end of the script call the function.