[Tutor] new print statement + time module

Ken Oliver ksterling at mindspring.com
Sat Feb 28 09:01:16 CET 2009



-----Original Message-----
>From: spir <denis.spir at free.fr>
>Sent: Feb 28, 2009 2:16 AM
>To: tutor at python.org
>Subject: Re: [Tutor] new print statement + time module
>
>Le Sat, 28 Feb 2009 06:34:07 +0200,
>George Wahid <geoterium at gmail.com> s'exprima ainsi:
>
>> I downloaded python 3.0.1 today and started experimenting with the new
>> print statement.
>> 
>> >>>import time
>> >>>for l in 'the answer':
>> ...    print(l,end='')
>> ...    time.sleep(0.1)
>> 
>> the code is supposed to print "the answer" with a 0.1 second long
>> pause between the letters. instead, it waits for 1 second (
>> 0.1*len("the answer") seconds ) and then prints "the answer". what am
>> I doing wrong ?
>
>Indeed, it does the same for me with python 2.5:
>
>from time import sleep
>for c in "1234567890":
>	sleep(0.25)
>	print c,
>
>I guess python underlying outputs are managed like a queue that is flushed at certain points, eg whan a newline comes.
>Already noticed weird outputs messing up ordinary prints (~ sys.stdout) and exceptions messages (sys.stderr). I'd like to know more about that.
>
>> both replacing print(l,end='') with print(l) or using the msvcrt
>> module instead of the print function work fine.
>
>The same with py2.5. Without the ',', all is fine. Maybe there is a trick to force python printing ot in due time, but I have no idea, sorry.
>
>Denis
>------
>la vita e estrany
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor

The above code for the 2.5 version appears to work as expected in the command line versions of 2.5.

 .


More information about the Tutor mailing list