help understanding time.sleep() behavior

Gordon McMillan gmcm at hypernet.com
Sat Mar 11 01:28:04 CET 2000


Andy Fox wrote:
> 
> I would like my program to pause for a second within a loop, but instead
> it pauses for n seconds, where n is the number of iterations through the
> loop, then executes the other statements.
> 
> I'm running PythonWin on an NT machine.
> 
> Here's the (embarassingly simple) code:
> 
> >>> import time
> >>> for x in range (5)
> ... 	print x
> ... 	time.sleep(1)
> ...                    <-- pauses here for five seconds
> 0                      <-- then prints the values quickly
> 1
> 2
> 3
> 4

Your program does exactly what you think it does. Pythonwin 
just buffers output in a non-smooth manner. Run it under 
python.exe instead and you'll see.

- Gordon




More information about the Python-list mailing list