print and trailing white space

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maxime Biais

    print and trailing white space

    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
  • Peter Hansen

    #2
    Re: print and trailing white space

    Maxime Biais wrote:[color=blue]
    >
    > 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()[/color]

    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

    Comment

    • Maxime Biais

      #3
      Re: print and trailing white space

      Thu, 18 Sep 2003 17:33:41 -0400
      Peter Hansen <peter@engcorp. com> wrote:
      [color=blue]
      > 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.[/color]

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

      --
      Maxime Biais

      Comment

      • Peter Otten

        #4
        Re: print and trailing white space

        Maxime Biais wrote:
        [color=blue]
        > 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()
        >[/color]
        [color=blue][color=green][color=darkred]
        >>> class Out(object):[/color][/color][/color]
        .... def _set_softspace( self, value):
        .... pass
        .... def _get_softspace( self):
        .... return False
        .... softspace = property(_get_s oftspace, _set_softspace)
        .... def write(self, s):
        .... sys.stdout.writ e(s)
        ....[color=blue][color=green][color=darkred]
        >>> out = Out()
        >>> print >> out, "a", "b", "c"[/color][/color][/color]
        abc[color=blue][color=green][color=darkred]
        >>> print >> out, "x",[/color][/color][/color]
        x>>>

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

        Peter

        Comment

        • M-a-S

          #5
          Re: print and trailing white space

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

          "Peter Otten" <__peter__@web. de> wrote in message news:bkdas5$usv [email protected]...[color=blue]
          >[color=green][color=darkred]
          > >>> class Out(object):[/color][/color]
          > ... def _set_softspace( self, value):
          > ... pass
          > ... def _get_softspace( self):
          > ... return False
          > ... softspace = property(_get_s oftspace, _set_softspace)
          > ... def write(self, s):
          > ... sys.stdout.writ e(s)
          > ...[color=green][color=darkred]
          > >>> out = Out()
          > >>> print >> out, "a", "b", "c"[/color][/color]
          > abc[color=green][color=darkred]
          > >>> print >> out, "x",[/color][/color]
          > x>>>
          >
          > It's possible, but I'd rather go with write().
          > And, please, never ever substitute sys.stdout with a similar object.
          >
          > Peter[/color]


          Comment

          Working...