Printing and prompting adds a mysterious extra space

Christoph Haas email at christoph-haas.de
Sat Oct 1 19:35:14 EDT 2005


On Sat, Oct 01, 2005 at 05:09:48PM -0500, jepler at unpythonic.net wrote:
> Use sys.stdout.write instead of print.  It will solve these problems you are
> having.
> 
> If you really want to know what's going on, read the language manual,
> http://docs.python.org/ref/print.html It explains the behavior of this extra
> space, which is output by a successive 'print' statement.  The implementation
> uses an attribute called 'softspace', which is described in
> http://docs.python.org/lib/bltin-file-objects.html 

Thank you for the technical explanation. "print a,b" is nice to read
in simple Python programs. But when you need to get more control of
I/O it's better to know what's really happening inside.

So the "softspace" is always added after a "print a," statement but only
printed if Python thinks it is not at the beginning of a terminal line.
Interesting.

Again, thanks. I'll rest my case.

 Christoph
-- 
I'm still confused - just on a higher level now.
~
~
".signature" [Modified] 1 line --100%--                1,48         All



More information about the Python-list mailing list