print ending with comma

jamesthiele.usenet at gmail.com jamesthiele.usenet at gmail.com
Tue Jul 19 11:36:16 EDT 2005


I recently ran into the issue with 'print' were, as it says on the web
page called "Python Gotchas"
(http://www.ferg.org/projects/python_gotchas.html):

The Python Language Reference Manual says, about the print statement,

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:
+ -=
Note that there is no space after the '-'. (Tested on Win 2000 python
2.3.4, OS X 10.3.9 python 2.3 & 2.4)

I know that this is not a massively important issue, but can someone
explain what's going on?




More information about the Python-list mailing list