sleep() function, perhaps.

Christopher Koppler klapotec at chello.at
Tue Nov 25 01:14:20 EST 2003


On Tue, 25 Nov 2003 05:26:25 GMT, Ryan Spencer <jeder at earthlink.net>
wrote:

>
>Hello Everyone, 
>
>	I want to have a row of periods, separated by small, say, .5 second
>intervals between each other. Thus, for example, making it have the
>appearance of a progress "bar". 
>
>[code]
>import time
>
>sleep(.5)
>print "."
>sleep(.5)
>print "."
>[end code]
>
>But, it would (with those .5 second intervals)
>print out much like the following.
>
>.
>(pause)
>.
>(pause)
>
>I would rather those periods be on a single line, not printing on a new
>line each time.
>
>Any suggestions?

Try print with added comma or sys.stdout.write, like so:

>>> import time
>>> for i in range(10):
...     print '\b.',
...     time.sleep(1.5)
...
..........
>>> import sys
>>> for i in range(10):
...     sys.stdout.write('.')
...     time.sleep(0.5)
...
..........


--
Christopher




More information about the Python-list mailing list