Printing dots in sequence ('...')

B

beertje

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. How do I print dots - or anything for that matter - in
sequence without a space being inserted in between?

Thanks.
Björn
 
P

Peter Otten

beertje said:
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?
.... 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
 
L

Larry Bates

beertje said:
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. How do I print dots - or anything for that matter - in
sequence without a space being inserted in between?

Thanks.
Björn

I wrote this a donated to Python Cookbook some time ago, enjoy.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/299207

-Larry
 
L

Larry Bates

beertje said:
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. How do I print dots - or anything for that matter - in
sequence without a space being inserted in between?

Thanks.
Björn

See example here:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/299207

-Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,266
Latest member
DavidaAlla

Latest Threads

Top