newbie ``print`` question

gwhite gwhite at ti.com
Sun Sep 2 15:46:18 EDT 2012


On Sep 2, 10:45 am, Joel Goldstick <joel.goldst... at gmail.com> wrote:
> On Sun, Sep 2, 2012 at 1:23 PM, gwhite <gwh... at ti.com> wrote:
> > I can't figure out how to stop the "add a space at the beginning"
> > behavior of the print function.
>
> >>>> print 1,;print 2,
> > 1 2
>
> > See the space in between the 1 and the 2 at the output print to the
> > command console?
>
> > The help for print is:
>
> > "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."
>
> > So it is apparently doing what it is supposed to do.
>
> > Is there a way to stop this?  Or is there a different function that
> > will only print what you have in the formatted string?
>
> You can do it with string formatting.  My example shows 'old style'
> string formatting syntax.  There is a newer style.  You can learn
> about both from the online python docs.
>
>
>
> >>> print "%d%d" % (1,2)
> 12

For "real" stuff, I've been trying to use that.  I saw it in Beazley's
latest Essential text.

You're right, I can construct a single string and then write it.  In
fact, it looks like it is a must unless using the 3.2/3.3 version of
`print`.




More information about the Python-list mailing list