Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8498
| From | Duncan Booth <duncan.booth@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: what's the big deal for print() |
| Date | 2011-06-27 08:23 +0000 |
| 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> |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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