Python Forum

Full Version: How to Loop A Script within itself?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.


How would I write a python script that after it gets to the end of itself, waits like one hour, and then restarts itself? How do you make it so it restarts itself on its own without you having to manually open and close the program? I've looked online for a while but haven't found what I'm looking for specifically. I just need a thing to google or pip install. If this is an obvious thing, sorry bout that.

example code input:
print('whateves')
**wait an hour and loop**

***python prints 'whateves', then waits one hour, and prints 'whateves' again, on and on forever and ever as long as my computer is turned on and not asleep.
you can use python builtin sched.
see: https://pymotw.com/3/sched/
thank you Tongue