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 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: References: <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 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