Printing dots in single-line

Duncan Booth duncan at NOSPAMrcp.co.uk
Mon Nov 17 05:01:54 EST 2003


Bob Gailer <bgailer at alum.rpi.edu> wrote in
news:mailman.779.1069023820.702.python-list at python.org: 

>>while 1:
>>     print '.',
>>
>>Prints line of dots separated by a whitespace (. . . . . . etc). Is
>>there a way I can get it to display them without that white space
>>(.......etc)? 
> 
> Try (depending on the output device)
> while 1:
>      print '.\b',

Yuck.

Either suppress the whitespace:

import sys
for i in range(10):
    sys.stdout.softspace=False
    print '.',

or, much simpler, just don't use print:

for i in range(10):
    sys.stdout.write('.')

The reason I say that 'write' is simpler is that the softspace attribute 
works in a slightly confusing manner. You have to set it false every time 
before you print something if you don't want Python putting a leading space 
before the string it outputs. It gets sets true after each item that is 
printed unless a newline has just been output.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list