11

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) 

Where shall I put the sleep(6) in this?

3 Answers 3

24

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 

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) 

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

Sign up to request clarification or add additional context in comments.

5 Comments

map(firefox.open, ['http://www.bing.com/search?q=' + str(i) for i in range(x))], [2] * x) Where shall I put the sleep(6) in this?
@user3072758, You will have to un-comprehend your list-comprehension and write it out in traditional style
@user3072758, I know how disappointing it can be when you write a great list-comprehension and then you have to split it open like some kind of savage. :)
I literally have no idea what to do now. I guess I could go back to just running this multiple times. I wanted to put the delay in so that Firefox is capable of registering all of the queries instead of “almost” all of the queries.
@user3072758, Can you blow out your code and write tradition for-loops. If yes, then I can help you. I don't really know about firefox.open and stuff so I am currently not understanding.
1

Or if you want it to start on one and emulate a stopwatch:

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) 

Comments

0

Yes it is possible in python you should use 'time' module:

 >>> 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 

output :

 1 2 3 4 5 6 7 8 9 10 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.