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

MRAB python at mrabarnett.plus.com
Wed Jan 11 04:47:21 CET 2012


On 11/01/2012 03:14, Guido van Rossum wrote:
> On Tue, Jan 10, 2012 at 6:36 PM, MRAB <python at mrabarnett.plus.com
> <mailto:python at mrabarnett.plus.com>> wrote:
>
>     On 11/01/2012 01:59, Nick Coghlan wrote:
>
>         On Tue, Jan 10, 2012 at 8:15 PM, Masklinn<masklinn at masklinn.net
>         <mailto:masklinn at masklinn.net>__>
>         wrote:
>
>                 So the keyword argument means "do or don't call flush()
>                 method of
>                 the file."
>
>             That's not clear from its name since the flushing behavior can
>             depend on the underlying stream type. force_flush would be
>             closer
>             to the actual meaning of the param.
>
>
>         +0 for being able to write print("whatever", force_flush=True)
>         instead of having to do:
>
>         import sys # somewhere in the file
>
>      > print("whatever")
>
>         sys.stdout.flush()
>
>     Given that 'print' is a function in Python 3, it's easy to redefine it
>     to flush. I've done it on occasion.
>
>
> Heh, that's exactly why we made it a function. So is adding e.g. a
> force_flush flag -- though personally I would be fine calling it "flush"
> despite the possibility that the underlying stream might still flush
> when it is not explicitly requests.
>
Even a buffered stream flushes sometime. :-)



More information about the Python-ideas mailing list