[Python-ideas] Pythonic buffering in Py3 print()
Guido van Rossum
guido at python.org
Mon Jan 9 18:52:21 CET 2012
This has nothing to do with print or print(). There are no flush() calls
implied by print/print() calls, nor should there be(*). print/print()
simply calls sys.stdout.write() one or more times, the final call usually
being sys.stdout.write('\n') which will trigger a flush() if the file is
line-buffered -- but if you use a trailing comma (Python 2) or end=...
(Python 3) the last thing written is not '\n' and no flush() will be
Whether writing \n flushes or not depends on the platform, the Python
version and implementation, and the environment (e.g. most platforms
automatically turn on line buffering for files known to be associated with
a terminal emulator or other interactive device, assuming there's an easy
way to tell).
(*) There are plenty of apps that construct their output using many
print/print() calls, and for which flushing after each call would be quite
unnecessary and potentially cause lots of redundant I/O operations,
ultimately slowing down the app. Apps that need flushing should call
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas