Wil*_*yce 730
from time import sleep
sleep(0.05)
Run Code Online (Sandbox Code Playgroud)
ya2*_*a23 69
请注意,如果您依赖睡眠时间恰好为 50毫秒,那么您将无法获得.它只是关于它.
Dan*_*son 60
import time
time.sleep(50 / 1000)
Run Code Online (Sandbox Code Playgroud)
小智 5
有一个名为“时间”的模块可以帮助您。我知道两种方法:
sleep
Sleep(参考)要求程序等待,然后执行其余的代码。
有两种使用睡眠的方法:
import time # Import whole time module
print("0.00 seconds")
time.sleep(0.05) # 50 milliseconds... make sure you put time. if you import time!
print("0.05 seconds")
Run Code Online (Sandbox Code Playgroud)
第二种方式不导入整个模块,而只是休眠。
from time import sleep # Just the sleep function from module time
print("0.00 sec")
sleep(0.05) # Don't put time. this time, as it will be confused. You did
# not import the whole module
print("0.05 sec")
Run Code Online (Sandbox Code Playgroud)
如果您需要运行循环,这种方式很有用。但是这个稍微复杂一些。
time_not_passed = True
from time import time # You can import the whole module like last time. Just don't forget the time. before to signal it.
init_time = time() # Or time.time() if whole module imported
print("0.00 secs")
while True: # Init loop
if init_time + 0.05 <= time() and time_not_passed: # Time not passed variable is important as we want this to run once. !!! time.time() if whole module imported :O
print("0.05 secs")
time_not_passed = False
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
421736 次 |
| 最近记录: |