[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

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

seberino

1/23/2008 2:03:00 PM

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
4 Answers

Diez B. Roggisch

1/23/2008 2:12:00 PM

0

seberino@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.)

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

Diez

Mike Kent

1/23/2008 3:14:00 PM

0

On Jan 23, 9:03 am, "seber...@spawar.navy.mil"
<seber...@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

print "%s%s" % ("foo", "bar") ## If "%s%s" doesn't violate your
condition of not defining a string variable, I'm not sure.

seberino

1/23/2008 7:43:00 PM

0

On Jan 23, 6:12 am, "Diez B. Roggisch" <de...@nospam.web.de> wrote:

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

Diez

Thanks. Beautiful! I <3 Python!

Chris

Ben Finney

1/23/2008 9:35:00 PM

0

"seberino@spawar.navy.mil" <seberino@spawar.navy.mil> writes:

> On Jan 23, 6:12 am, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
>
> > sys.stdout.write("foo")
> > sys.stdout.write("bar")
>
> Diez
>
> Thanks. Beautiful! I <3 Python!

Even better, this form will survive unchanged into Python 3, whereas
the 'print' statement will undergo some changes in syntax and
perhaps semantics.

--
\ "Free thought is a necessary, but not a sufficient, condition |
`\ for democracy." â??Carl Sagan |
_o__) |
Ben Finney