[docs] [issue11633] Document that print may need explicit flushing

Terry J. Reedy report at bugs.python.org
Mon Jan 9 20:59:39 CET 2012


Terry J. Reedy <tjreedy at udel.edu> added the comment:

The current doc says

"print([object, ...], *, sep=' ', end='\n', file=sys.stdout) 
Print object(s) to the stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.

All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no object is given, print() will just write end.

The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used."

(The bit about None, said twice, could be factored out and said once after the second sentence.)

This is exactly what print does and Guido today (Python ideas) said that is what it should do and that "Apps that need flushing should call flush()." So a code change is rejected.

The issue title was incorrect. The print function does not do any buffering. The file object it writes to may. Even sys.stdout may or may not. 

We could add at the end a sentence or two something like

"Output buffering is determined by *file*. Call file.flush() to ensure, for instance, immediate appearance on a screen."

----------
assignee:  -> docs at python
components: +Documentation -Interpreter Core
nosy: +docs at python
stage:  -> needs patch
title: Document that print buffers output when end='' -> Document that print may need explicit flushing

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11633>
_______________________________________


More information about the docs mailing list