flushing of print statements ending with comma

G

Grebekel

I have recently noticed that print statements ending with a comma are
not immediately flushed. This is evident when such statement is
executed before a very long operation (a big loop for instance).

Example:

<code>
print 'Take a walk, because this will take a while...',
i = 0
while i < 10**10:
i += 1
print "we're done!"
</code>

Here the first string is not printed until the second print statement.
If the second print statement is removed then the string is not
printed until the end of the program. Apparently, python does not
flush the stdout buffer until it is ordered to do so either explicitly
or by a print statement not ending with a comma.

Using sys.std.flush after the print fixes this issue, but doing so
each time seems cumbersome and somewhat counterintuitive.

Is there some reasoning behind this behavior or is it a bug?

Python version 2.5.1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top