Getting rid of extra spaces in print

Laurent Martin laurent at lfmm.org
Sun May 28 08:53:46 CEST 2000


Hi,

I've just started learning Python. I try to write a simple script that
reads a file one character at a time and then prints it.  Thus I wrote: 

f = open('toto.src','r')

car = f.read(1)
while len(car):
    print car,
f.close()

Unfortunately the 'print' function adds an extra space between my 
characters.  I've found a solution on Deja.com: to set
sys.stdout.softspace to 0 before each call to print.  This works but is
there a simpler and more elegant solution to this problem?

Laurent.







More information about the Python-list mailing list