Printing dots in sequence ('...')

Peter Otten __peter__ at web.de
Tue May 22 04:21:24 EDT 2007


beertje wrote:

> This is a very newbie question for my first post, perhaps
> appropriately.
> 
> I want to print '....' gradually, as a progress indicator. I have a
> for-loop that every 10 steps executes:
> print '.',
> 
> This results in something like 'Loading. . . .', whereas I want
> 'Loading....'
> 
> A pet peeve, I can't for the life of me figure out how to get this
> desired output. 

I love understatement.

> How do I print dots - or anything for that matter - in 
> sequence without a space being inserted in between?

>>> import sys, time
>>> for i in range(10):
...     sys.stdout.write(".")
...     sys.stdout.flush()
...     time.sleep(.1) 
...
..........>>>

write() does the writing, flush() is to defeat the buffering; without it the
dots would be withhold until the next newline. The time.sleep() call is
that you can see it is actually one dot at a time.

Peter



More information about the Python-list mailing list