Re: print function and unwanted trailing space

2013-09-12 Thread Albert Hopkins
On Wed, Sep 11, 2013, at 07:36 AM, Wayne Werner wrote: > On Sat, 31 Aug 2013, candide wrote: > > # - > > for i in range(5): > >print(i, end=' ') # <- The last ' ' is unwanted > > print() > > # - > > Then why not define end='' instead?

Re: print function and unwanted trailing space

2013-09-11 Thread Wayne Werner
On Sat, 31 Aug 2013, candide wrote: # - for i in range(5): print(i, end=' ') # <- The last ' ' is unwanted print() # - Then why not define end='' instead? -W -- https://mail.python.org/mailman/listinfo/python-list

Re: print function and unwanted trailing space

2013-08-31 Thread Terry Reedy
On 8/31/2013 7:15 PM, Joshua Landau wrote: On 31 August 2013 23:08, Chris Angelico wrote: On Sun, Sep 1, 2013 at 1:43 AM, Oscar Benjamin wrote: On 31 August 2013 16:30, Chris Angelico wrote: but doesn't solve all the cases (imagine a string or an iterator). Similar but maybe simpler, and

Re: print function and unwanted trailing space

2013-08-31 Thread Joshua Landau
On 31 August 2013 23:08, Chris Angelico wrote: > On Sun, Sep 1, 2013 at 1:43 AM, Oscar Benjamin > wrote: >> On 31 August 2013 16:30, Chris Angelico wrote: but doesn't solve all the cases (imagine a string or an iterator). >>> >>> Similar but maybe simpler, and copes with more arbitrary

Re: print function and unwanted trailing space

2013-08-31 Thread Chris Angelico
On Sun, Sep 1, 2013 at 1:43 AM, Oscar Benjamin wrote: > On 31 August 2013 16:30, Chris Angelico wrote: >>> >>> but doesn't solve all the cases (imagine a string or an iterator). >> >> Similar but maybe simpler, and copes with more arbitrary iterables: >> >> it=iter(range(5)) >> print(next(it), en

Re: print function and unwanted trailing space

2013-08-31 Thread candide
Le 31/08/2013 15:59, Peter Otten a écrit : To make it crystal clear, the above was to illustrate the algorithm used in Python 2, not a suggestion. Ok sorry, I misinterpreted. > I still think you should live with a trailing space Are you sure ? The following code #

Re: print function and unwanted trailing space

2013-08-31 Thread candide
Le 31/08/2013 12:31, Peter Otten a écrit : with `softspace` saved as a file attribute, is gone in Python3. After reading http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function I understand what you meant by "softspace". Thanks. -- http://mail.python.org/mailman/listinfo/python-l

Re: print function and unwanted trailing space

2013-08-31 Thread Oscar Benjamin
On 31 August 2013 16:30, Chris Angelico wrote: >> >> but doesn't solve all the cases (imagine a string or an iterator). > > Similar but maybe simpler, and copes with more arbitrary iterables: > > it=iter(range(5)) > print(next(it), end='') > for i in it: > print('',i, end='') If you want to w

Re: print function and unwanted trailing space

2013-08-31 Thread Chris Angelico
On Sat, Aug 31, 2013 at 11:33 PM, candide wrote: > The if instruction imposes useless testing (we know in advance the problem > to occur at the very end of the loop) and useless writing (writing ''). > > The following is clearer > > # - > n=5 > for i in range(n-1): > pr

Re: print function and unwanted trailing space

2013-08-31 Thread Steven D'Aprano
On Sat, 31 Aug 2013 14:59:17 +0200, candide wrote: > Le 31/08/2013 13:16, Steven D'Aprano a écrit : > > >> Of course it does. Have you actually tried it? > > > Of course I did, redirecting the output to a file in order to spot an > eventually trailing space. I did the same for the Python 3 cod

Re: print function and unwanted trailing space

2013-08-31 Thread Peter Otten
candide wrote: > Le 31/08/2013 12:31, Peter Otten a écrit : > > softspace = False > > for i in range(5): > > if softspace: > > print(end=" ") > > print(i, end="") > > softspace = True > > print() > > > The if instruction imposes useless testing (we know in advance

Re: print function and unwanted trailing space

2013-08-31 Thread candide
Le 31/08/2013 13:24, Ned Batchelder a écrit : For a beginner course, the trailing space is fine, use this code. I was really expecting there was a trick but I'll follow your advice, after all the trailing space is invisible! Nevertheless, this can be quite annoying. For instance, some autom

Re: print function and unwanted trailing space

2013-08-31 Thread candide
Le 31/08/2013 12:31, Peter Otten a écrit : > softspace = False > for i in range(5): > if softspace: > print(end=" ") > print(i, end="") > softspace = True > print() The if instruction imposes useless testing (we know in advance the problem to occur at the very end of the

Re: print function and unwanted trailing space

2013-08-31 Thread candide
Le 31/08/2013 13:16, Steven D'Aprano a écrit : Of course it does. Have you actually tried it? Of course I did, redirecting the output to a file in order to spot an eventually trailing space. I did the same for the Python 3 code. -- http://mail.python.org/mailman/listinfo/python-list

Re: print function and unwanted trailing space

2013-08-31 Thread Oscar Benjamin
On 31 August 2013 12:16, Steven D'Aprano wrote: > On Sat, 31 Aug 2013 10:17:23 +0200, candide wrote: > >> What is the equivalent in Python 3 to the following Python 2 code: >> >> # - >> for i in range(5): >> print i, >> # - >> >> ? >> >>

Re: print function and unwanted trailing space

2013-08-31 Thread Peter Otten
Steven D'Aprano wrote: > On Sat, 31 Aug 2013 10:17:23 +0200, candide wrote: > >> What is the equivalent in Python 3 to the following Python 2 code: >> >> # - >> for i in range(5): >> print i, >> # - >> >> ? >> >> Be careful that the

Re: print function and unwanted trailing space

2013-08-31 Thread Ned Batchelder
On 8/31/13 4:17 AM, candide wrote: What is the equivalent in Python 3 to the following Python 2 code: # - for i in range(5): print i, # - ? Be careful that the above code doesn't add a trailing space after the last number in the lis

Re: print function and unwanted trailing space

2013-08-31 Thread Steven D'Aprano
On Sat, 31 Aug 2013 10:17:23 +0200, candide wrote: > What is the equivalent in Python 3 to the following Python 2 code: > > # - > for i in range(5): > print i, > # - > > ? > > Be careful that the above code doesn't add a trailing spac

Re: print function and unwanted trailing space

2013-08-31 Thread Peter Otten
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

Re: print function and unwanted trailing space

2013-08-31 Thread candide
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 learner

Re: print function and unwanted trailing space

2013-08-31 Thread Andreas Perstinger
On 31.08.2013 10:17, candide wrote: What is the equivalent in Python 3 to the following Python 2 code: # - for i in range(5): print i, # - ? How about >>> print(" ".join(str(i) for i in range(5))) 0 1 2 3 4 Bye, Andreas -- ht

print function and unwanted trailing space

2013-08-31 Thread candide
What is the equivalent in Python 3 to the following Python 2 code: # - for i in range(5): print i, # - ? Be careful that the above code doesn't add a trailing space after the last number in the list, hence the following Python 3 code