print with no newline
Peter Otten
__peter__ at web.de
Fri Sep 3 10:36:31 EDT 2004
Paul Watson wrote:
> I thought that using a comma at the end of a print statement would
> suppress
> printing of a newline. Am I misunderstanding this feature? How can I use
> print and not have a newline appended at the end?
I thought that, too. It turns out that Python writes an additional newline
on exit if the softspace flag is set. So
$ python -c "import sys; print 'here',; sys.stdout.softspace = False" >
tmp.txt
$ od -c tmp.txt
0000000 h e r e
0000004
is a viable if ugly workaround.
Peter
More information about the Python-list
mailing list