for循环迭代之间的延迟(python) [英] Delay between for loop iteration (python)

查看:1276
本文介绍了for循环迭代之间的延迟(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在Python中可能吗?我用Python写了一个很棒的循环/脚本,我想尽可能增加这种延迟.

Is this possible in Python? I wrote a great loop/script in Python and I’d like to add this delay to it if at all possible.

map(firefox.open, ['http://www.bing.com/search?q=' + str(i) for i in range(x))], [2] * x)

我应该将sleep(6)放在哪里?

推荐答案

您可以使用time.sleep(some_seconds)来做到这一点.

You can do that using time.sleep(some_seconds).

from time import sleep

for i in range(10):
    print i
    sleep(0.5)    #in seconds

实施

这是一个很酷的实现:(将其粘贴到.py文件中并运行)

Implementation

Here is a cool little implementation of that: (Paste it in a .py file and run it)

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)表示范围(x))中的i,[2] * x)

map(firefox.open, ['http://www.bing.com/search?q=' + str(i) for i in range(x))], [2] * x)

这篇关于for循环迭代之间的延迟(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆