[Python-ideas] Pythonic buffering in Py3 print()

Paul Moore p.f.moore at gmail.com
Mon Jan 9 13:50:23 CET 2012


On 9 January 2012 12:21, anatoly techtonik <techtonik at gmail.com> wrote:
>> Python doesn't do any extra buffering or flushing. Usually your
>> terminal emulator line-buffers stdout. If you don't print a newline
>> (in Python 2 OR 3) then it doesn't show up until you either flush
>> (sys.stdout.flush()) or send a newline.
>
> I assume you use Linux. Do you agree that for cross-platform language some
> behavior should be made consistent?

No. (At least not for 2.x). The Python 2.x position has always been
that the IO layer is a relatively thin wrapper over the platform
behaviour, and so this sort of platform dependent behaviour should not
come as a surprise to anyone.

For Python 3.x, the IO layer was reworked to be more platform-neutral,
and I would expect consistent behaviour across platforms there. And
the behaviour I would expect (given that stdout is a buffered text
stream) is that output from print would be buffered until an implicit
or explicit flush. And that is exactly what happens.

So I'd say that you're 100% right in what you say as regards Python 3,
and that is exactly what is happening. The difference with Python 2 is
precisely one of those backward-incompatible breaks that required the
2->3 major version change.

Characterising a carefully thought out change implemented in a way
that minimises backward compatibility issues as a "bug", is at best
unfair and dismissive of the work that was put into this.

Paul.



More information about the Python-ideas mailing list