print and trailing white space

Discussion in 'Python' started by Maxime Biais, Sep 18, 2003.

  1. Maxime Biais

    Maxime Biais Guest

    Hello,

    I know how to print a string without the trailing newline with a coma
    like :

    print "hello word",

    but this example add a white space after the string :(

    Do you know how to avoid this white space without using write()

    --
    Maxime Biais
    Maxime Biais, Sep 18, 2003
    #1
    1. Advertising

  2. Maxime Biais

    Peter Hansen Guest

    Maxime Biais wrote:
    >
    > Hello,
    >
    > I know how to print a string without the trailing newline with a coma
    > like :
    >
    > print "hello word",
    >
    > but this example add a white space after the string :(
    >
    > Do you know how to avoid this white space without using write()


    What's wrong with write() ? Print is merely provided for convenience.
    When it's not doing what you want, you are supposed to use write(),
    not come up with weird hacks for print.

    -Peter
    Peter Hansen, Sep 18, 2003
    #2
    1. Advertising

  3. Maxime Biais

    Maxime Biais Guest

    Thu, 18 Sep 2003 17:33:41 -0400
    Peter Hansen <> wrote:

    > What's wrong with write() ? Print is merely provided for convenience.
    > When it's not doing what you want, you are supposed to use write(),
    > not come up with weird hacks for print.


    ok sorry, I believed write was not buffered. I just read the library
    reference part on write() and see I was wrong.

    --
    Maxime Biais
    Maxime Biais, Sep 18, 2003
    #3
  4. Maxime Biais

    Peter Otten Guest

    Maxime Biais wrote:

    > I know how to print a string without the trailing newline with a coma
    > like :
    >
    > print "hello word",
    >
    > but this example add a white space after the string :(
    >
    > Do you know how to avoid this white space without using write()
    >


    >>> class Out(object):

    .... def _set_softspace(self, value):
    .... pass
    .... def _get_softspace(self):
    .... return False
    .... softspace = property(_get_softspace, _set_softspace)
    .... def write(self, s):
    .... sys.stdout.write(s)
    ....
    >>> out = Out()
    >>> print >> out, "a", "b", "c"

    abc
    >>> print >> out, "x",

    x>>>

    It's possible, but I'd rather go with write().
    And, please, never ever substitute sys.stdout with a similar object.

    Peter
    Peter Otten, Sep 18, 2003
    #4
  5. Maxime Biais

    M-a-S Guest

    Thank you for a great example anyway!
    M-a-S

    "Peter Otten" <> wrote in message news:bkdas5$usv$07$-online.com...
    >
    > >>> class Out(object):

    > ... def _set_softspace(self, value):
    > ... pass
    > ... def _get_softspace(self):
    > ... return False
    > ... softspace = property(_get_softspace, _set_softspace)
    > ... def write(self, s):
    > ... sys.stdout.write(s)
    > ...
    > >>> out = Out()
    > >>> print >> out, "a", "b", "c"

    > abc
    > >>> print >> out, "x",

    > x>>>
    >
    > It's possible, but I'd rather go with write().
    > And, please, never ever substitute sys.stdout with a similar object.
    >
    > Peter
    M-a-S, Sep 19, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leo
    Replies:
    0
    Views:
    454
  2. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,890
    Bryan Bullard
    Jul 11, 2003
  3. Ben C
    Replies:
    6
    Views:
    2,154
    Leif K-Brooks
    Jan 28, 2007
  4. ucfcpegirl06

    Getting Rid of Trailing white spaces

    ucfcpegirl06, Jul 22, 2005, in forum: C++
    Replies:
    4
    Views:
    432
    ucfcpegirl06
    Jul 23, 2005
  5. candide
    Replies:
    20
    Views:
    226
    Albert Hopkins
    Sep 12, 2013
Loading...

Share This Page