print ending with comma
André Roberge
andre.roberge at gmail.com
Tue Jul 19 11:58:49 EDT 2005
jamesthiele.usenet at gmail.com wrote:
[snip]
>
> A "\n" character is written at the end, unless the print statement ends
> with a comma.
>
> What it doesn't say is that if the print statement does end with a
> comma, a trailing space is printed.
> --
> But this isn't exactly correct either. If you run this program:
> import sys
> print '+',
> print '-',
> sys.stdout.write('=')
> print
> --
> the output is:
> + -=
[snip]
> I know that this is not a massively important issue, but can someone
> explain what's going on?
>
Actually, it is not a trailing space but a leading space
that is stored and displayed when print is called next.
>>> import sys
>>> print 'a',
a
>>> print 'b',
b
>>>
---
sys.stdout.write() does not include such a leading space.
Time to consult python.org about the print statement.:
[http://www.python.org/doc/2.0.1/ref/print.html]
...A space is written before each object is (converted and) written,
unless the output system believes it is positioned at the beginning of a
line...
Yep, another case of RTM :-)
André
More information about the Python-list
mailing list