Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8498

Re: what's the big deal for print()

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Duncan Booth <duncan.booth@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: what's the big deal for print()
Date 27 Jun 2011 08:23:30 GMT
Lines 44
Message-ID <Xns9F115F842E5CAduncanbooth@127.0.0.1> (permalink)
References <d3558c5d-0fe6-4da7-843d-c2f45b2bf869@y13g2000yqy.googlegroups.com> <iu3kb0$oh8$1@reader1.panix.com> <4e055da9$0$29970$c3e8da3$5496439d@news.astraweb.com>
Reply-To duncan.booth@suttoncourtenay.org.uk
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-1
Content-Transfer-Encoding 8bit
X-Trace individual.net BRQeOjXcFiftC3Ek/oMingK9HtFeMTs0xEkWilVFSgvOBbm+Zu
Cancel-Lock sha1:COnUbMMu3buFqt376E5S9iXo+nE=
User-Agent Xnews/2006.08.24 Hamster/2.1.0.11
X-Face .C;/v3#w@2k.C(.1v-}d=`|7AQ-%,#A$0ZGtAkLPvuawAM>3#D,pXaAb31%(=Gn2ZZK/Z~fd0y4't5iKK~F":}F2*|\mQYX+BUr4ZM*|+`@o-TKzFGwsJnan{)*b~QJ-Fu^u'$$nYV
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8498

Show key headers only | View raw


steve+comp.lang.python@pearwood.info wrote:

> Unfortunately, while that gets rid of the newline, it also leaves 
spaces
> between items:
> 
>>>> def example():
> ...     print 1,
> ...     print 2,
> ...     print 3
> ...
>>>> example()
> 1 2 3
> 
> Here's the Python 3 version:
> 
>>>> def example():
> ...     print(1, sep='', end='')
> ...     print(2, sep='', end='')
> ...     print(3, sep='')
> ...
>>>> example()
> 123
> 
> 
> To get the same result in Python 2, you have to use sys.stdout.write
().
> 

That isn't entirely true: you could set the `softspace` attribute on 
sys.stdout, but that is even messier.

>>> def foo():
...     print 1,
...     sys.stdout.softspace=0
...     print 2,
...     sys.stdout.softspace=0
...     print 3
...
>>> foo()
123

-- 
Duncan Booth http://kupuguy.blogspot.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

what's the big deal for print() pipehappy <pipehappy@gmail.com> - 2011-06-24 19:39 -0700
  Re: what's the big deal for print() John Gordon <gordon@panix.com> - 2011-06-25 03:23 +0000
    Re: what's the big deal for print() steve+comp.lang.python@pearwood.info - 2011-06-25 14:01 +1000
      Re: what's the big deal for print() Duncan Booth <duncan.booth@invalid.invalid> - 2011-06-27 08:23 +0000
  Re: what's the big deal for print() Terry Reedy <tjreedy@udel.edu> - 2011-06-24 23:54 -0400

csiph-web