[Tutor] trivial simple program..can it be made more concise?

Dave Angel davea at davea.name
Sat Feb 14 19:17:37 CET 2015


On 02/14/2015 07:51 AM, Steven D'Aprano wrote:
> On Sat, Feb 14, 2015 at 06:40:56AM -0500, Dave Angel wrote:
>> On 02/14/2015 04:07 AM, Steven D'Aprano wrote:
>>> On Sat, Feb 14, 2015 at 03:17:28AM +0000, steve10brink at comcast.net wrote:
>
> [...]
>>>> for i in range (a):
>>>>      print i, '\r',
> [...]
>
>>> BUT I'm not sure why you are worried about making it more concise when
>>> your code doesn't do what you want, as far as I can tell. You want the
>>> counter to be written on the same line, not 640 thousand lines, but when
>>> I try it, I get each number written to a different line.
>>
>> That's probably because you've dropped the trailing comma that the OP
>> used in the print statements.
>
> So I did :-(
>
> Have I mentioned recently just how awesome Python 3's print is?
>
> for i in range(100000):
>      print(i, end='\r')
>
> Much nicer :-)
>
>

Agreed.  But don't you need " \r" so when you're counting down you don't 
have the trailing crud?  The space was implicit on Python 2, because it 
mistakenly thought the code was printing two elements.


-- 
DaveA


More information about the Tutor mailing list