[Python-checkins] cpython (3.4): Issue 22492: Be explicit that print does not support binary mode files.

terry.reedy python-checkins at python.org
Wed Oct 1 21:40:11 CEST 2014


https://hg.python.org/cpython/rev/9b519f72860a
changeset:   92719:9b519f72860a
branch:      3.4
parent:      92717:0c8f41ca9c94
user:        Terry Jan Reedy <tjreedy at udel.edu>
date:        Wed Oct 01 15:37:42 2014 -0400
summary:
  Issue 22492: Be explicit that print does not support binary mode files.
Original patch by Georg Brandl.

files:
  Doc/library/functions.rst |  13 ++++++++-----
  1 files changed, 8 insertions(+), 5 deletions(-)


diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -1083,8 +1083,8 @@
 
 .. function:: print(*objects, sep=' ', end='\\n', file=sys.stdout, flush=False)
 
-   Print *objects* to the stream *file*, separated by *sep* and followed by
-   *end*.  *sep*, *end* and *file*, if present, must be given as keyword
+   Print *objects* to the text 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 :func:`str` does and
@@ -1094,9 +1094,12 @@
    *end*.
 
    The *file* argument must be an object with a ``write(string)`` method; if it
-   is not present or ``None``, :data:`sys.stdout` will be used.  Whether output
-   is buffered is usually determined by *file*, but if the  *flush* keyword
-   argument is true, the stream is forcibly flushed.
+   is not present or ``None``, :data:`sys.stdout` will be used.  Since printed
+   arguments are converted to text strings, :func:`print` cannot be used with
+   binary mode file objects.  For these, use ``file.write(...)`` instead.
+
+   Whether output is buffered is usually determined by *file*, but if the
+   *flush* keyword argument is true, the stream is forcibly flushed.
 
    .. versionchanged:: 3.3
       Added the *flush* keyword argument.

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list