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


Groups > comp.lang.python > #53341

Re: print function and unwanted trailing space

From Peter Otten <__peter__@web.de>
Subject Re: print function and unwanted trailing space
Date 2013-08-31 12:31 +0200
Organization None
References <5221a693$0$2059$426a74cc@news.free.fr> <mailman.405.1377938644.19984.python-list@python.org> <5221b68b$0$2280$426a74cc@news.free.fr>
Newsgroups comp.lang.python
Message-ID <mailman.406.1377945101.19984.python-list@python.org> (permalink)

Show all headers | View raw


candide wrote:

> Le 31/08/2013 10:43, Andreas Perstinger a écrit :
> 
>  > How about
>  >
>  >  >>> print(" ".join(str(i) for i in range(5)))
>  > 0 1 2 3 4
>  >
> 
> 
> Thanks for your answer. The output is stricly the same but the code
> doesn't suit my needs :
> 
> 1) I'm porting to Python 3 a Python 2 full beginner course : the
> learners are not aware of the join method nor the str type nor
> generators stuff;
> 2) Your code introduce a (sometimes) useless conversion to str (consider
> a string instead of range(5)).

You are out of luck, the softspace mechanism, roughly

softspace = False
for i in range(5):
    if softspace:
        print(end=" ")
    print(i, end="")
    softspace = True
print()

with `softspace` saved as a file attribute, is gone in Python3. But I don't 
think that someone who doesn't know it existed will miss the feature.

Maybe you can allow for /some/ magic and introduce your students to

print(*range(5))

early-on.

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


Thread

print function and unwanted trailing space candide <candide@free.invalid> - 2013-08-31 10:17 +0200
  Re: print function and unwanted trailing space Andreas Perstinger <andipersti@gmail.com> - 2013-08-31 10:43 +0200
    Re: print function and unwanted trailing space candide <candide@free.invalid> - 2013-08-31 11:25 +0200
      Re: print function and unwanted trailing space Peter Otten <__peter__@web.de> - 2013-08-31 12:31 +0200
        Re: print function and unwanted trailing space candide <candide@free.invalid> - 2013-08-31 15:33 +0200
          Re: print function and unwanted trailing space Peter Otten <__peter__@web.de> - 2013-08-31 15:59 +0200
            Re: print function and unwanted trailing space candide <candide@free.invalid> - 2013-08-31 17:58 +0200
          Re: print function and unwanted trailing space Chris Angelico <rosuav@gmail.com> - 2013-09-01 01:30 +1000
          Re: print function and unwanted trailing space Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-08-31 16:43 +0100
          Re: print function and unwanted trailing space Chris Angelico <rosuav@gmail.com> - 2013-09-01 08:08 +1000
          Re: print function and unwanted trailing space Joshua Landau <joshua@landau.ws> - 2013-09-01 00:15 +0100
          Re: print function and unwanted trailing space Terry Reedy <tjreedy@udel.edu> - 2013-08-31 19:57 -0400
        Re: print function and unwanted trailing space candide <candide@free.invalid> - 2013-08-31 17:51 +0200
  Re: print function and unwanted trailing space Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-31 11:16 +0000
    Re: print function and unwanted trailing space Peter Otten <__peter__@web.de> - 2013-08-31 14:27 +0200
    Re: print function and unwanted trailing space Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-08-31 13:37 +0100
    Re: print function and unwanted trailing space candide <candide@free.invalid> - 2013-08-31 14:59 +0200
      Re: print function and unwanted trailing space Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-31 15:18 +0000
  Re: print function and unwanted trailing space Ned Batchelder <ned@nedbatchelder.com> - 2013-08-31 07:24 -0400
    Re: print function and unwanted trailing space candide <candide@free.invalid> - 2013-08-31 15:51 +0200
  Re: print function and unwanted trailing space Wayne Werner <wayne@waynewerner.com> - 2013-09-11 06:36 -0500
  Re: print function and unwanted trailing space Albert Hopkins <marduk@letterboxes.org> - 2013-09-12 15:25 -0400

csiph-web