how to set interval in python

# this makes program sleep in intervals
from time import time, sleep
while True:
    sleep(1 - time() % 1) # run every 1 second... you can change that
	# thing to run

Here is what the above code is Doing:
1. It’s running a while loop that will run forever.
2. It’s sleeping for 1 second minus the current time modulo 1.
3. It’s running the thing to run.

The reason it’s sleeping for 1 second minus the current time modulo 1 is so that it will run every second.

The reason it’s running the thing to run is so that it will run the thing to run.

The reason it’s running a while loop that will run forever is so that it will run a while loop that will run forever.