How avoid both a newline and a space between 2 print commands?

Remco Gerlich remco at gerlich.nl
Wed Jan 23 09:18:22 EST 2008


Hi,

Use

import sys
sys.stdout.write("foo")
sys.stdout.write("bar")

(and, possibly, sys.stdout.flush() to get the text to show up, it might wait
for the end of a complete line otherwise).

The alternative

import sys
print "foo",
sys.stdout.softspace=0
print "bar"

is just too hackish.

In Python 3, this will be improved!

Remco

On Jan 23, 2008 3:03 PM, seberino at spawar.navy.mil <seberino at spawar.navy.mil>
wrote:

> print "foo"
> print "bar"
>
> has a newline in between "foo" and "bar"
>
> print "foo",
> print "bar"
>
> has a space in between "foo" and "bar"
>
> How prevent ANYTHING from going in between "foo" and "bar" ??
>
> (Without defining a string variable.)
>
> Chris
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080123/aae41d5b/attachment-0001.html>


More information about the Python-list mailing list