Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'beginner': 0.05; 'output': 0.05; 'string': 0.09; 'feature.': 0.09; 'generators': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'useless': 0.09; 'python': 0.11; 'andreas': 0.16; 'attribute,': 0.16; 'luck,': 0.16; 'magic': 0.16; 'porting': 0.16; 'python3.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; "i'm": 0.30; 'code': 0.31; 'file': 0.32; 'maybe': 0.34; 'but': 0.35; 'false': 0.36; 'method': 0.36; 'thanks': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'conversion': 0.61; 'gone': 0.61; 'full': 0.61; 'course': 0.61; 'answer.': 0.68; 'miss': 0.74; 'introduce': 0.78; 'learners': 0.84; 'subject:space': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: print function and unwanted trailing space Date: Sat, 31 Aug 2013 12:31:32 +0200 Organization: None References: <5221a693$0$2059$426a74cc@news.free.fr> <5221b68b$0$2280$426a74cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p508488bf.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377945101 news.xs4all.nl 15892 [2001:888:2000:d::a6]:54439 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53341 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.