sleep() function, perhaps.

Ryan Spencer jeder at earthlink.net
Tue Nov 25 03:22:16 EST 2003


On Tue, 25 Nov 2003 06:14:20 +0000, Christopher Koppler wrote:

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


Heya', Thanks, 

	Actually though, None of those suggestions give me the desired result
I was looking for. I used both with the for loops, even the one with the
while loop, and for the first suggested it prints all of them out on new
lines (as opposed to all on the same line as I'd been hoping for) and the
second posts on one full line, yet, the periods still don't have pauses
between themselves. Perhaps something else is amiss?

As well, the trailing commas gives the exact same result as doing the
sys.stdout.write function. 

Is the code that you suggested giving you a result such as...

.(pause).(pause).(pause).

I raised everything up to a 1.5 second interval to exaggerate the results,
and I'm afraid I still don't notice the pauses. 

Perchance I simply need to remove whatever is terminating the line?
Does the time.sleep() function itself terminate a line? It would seem
if I could bypass that, it would allow the pauses and keep the periods
on one line.

Thank you for your advice though, It's highly appreciated. 

~Ryan




More information about the Python-list mailing list