Python中可能有this吗?我用Python编写了一个很棒的循环/脚本,如果可能的话,我想把这个延迟添加到它。
map(firefox.open, ['http://www.bing.com/search?q=' + str(i) for i in range(x))], [2] * x)
我应该将sleep(6)
放在哪里?
答案 0 :(得分:7)
您可以使用time.sleep(some_seconds)
。
from time import sleep
for i in range(10):
print i
sleep(0.5) #in seconds
这是一个很酷的小实现:(将其粘贴到.py文件中并运行它)
from time import sleep
for i in range(101):
print '\r'+str(i)+'% completed',
time.sleep(0.1)
地图(firefox.open,[' http://www.bing.com/search?q=' + str(i)for i in range(x))],[2] * x)
答案 1 :(得分:0)
是的,你可以在python中使用' time'模块:
>>> import time
>>> list1=[1,2,3,4,5,6,7,8,9,10]
>>> for i in list1:
time.sleep(1)#sleep for 1 second
print i
输出:
1
2
3
4
5
6
7
8
9
10
答案 2 :(得分:0)
或者,如果您希望它从一开始就模仿秒表:
import time
def count_to(number):
for i in range(number):
time.sleep(1)
i += 1
if i >= number:
print('Time is up')
break
print(i)