[Python-Dev] Backwards incompatible sys.stdout.write() behavior in Python 3 (Was: [Python-ideas] Pythonic buffering in Py3 print()) (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Fri Jan 13 17:19:08 CET 2012


On Fri, 13 Jan 2012 17:00:57 +0100 Xavier Morel <python-dev at masklinn.net> wrote:

FWIW this is not restricted to Linux (the same behavior change can be observed in OSX), and the script is overly complex you can expose the change with 3 lines

import sys sys.stdout.write('promt>') sys.stdin.read(1) Python 2 displays "prompt" and terminates execution on [Return], Python 3 does not display anything until [Return] is pressed. Interestingly, the -u option is not sufficient to make "prompt>" appear in Python 3, the stream has to be flushed explicitly unless the input is ~16k characters (I guess that's an internal buffer size of some sort)

"-u" forces line-buffering mode for stdout/stderr, which is already the default if they are wired to an interactive device (isattr() returning True).

But this was already rehashed on python-ideas and the bug tracker, and apparently Anatoly thought it would be a good idea to post on a third medium. Sigh.

Regards

Antoine.



More information about the Python-Dev mailing list