+ 1
Whats the python equivalent of the setInterval () function in javascript
7 odpowiedzi
+ 3
If you want to do something simple like put a pause in program execution, the .sleep() method of the time module would do it. For more complex things have a look at
https://stackoverflow.com/questions/2697039/JUMP_LINK__&&__python__&&__JUMP_LINK-equivalent-of-setinterval
+ 2
For example:
from time import sleep
i = 0
while i < 5:
print('hello')
i += 1
sleep(0.2)
+ 2
Thanks yall
Really really helpful
+ 1
what the sleep method does is to pause the function from executing for a particular time before it continue. it does not run the function at a set interval like setInterval() in JavaScript
+ 1
import time
from datetime import datetime
i = 0
def setInterval(second):
# code start
print(i)
print(datetime.now().strftime("%H:%M:%S"))
# code end
time.sleep(second)
setInterval(second)
setInterval(1)
0
Thanks boss Oyelakin Dotun Peter