Kaydet (Commit) 4e02c503 authored tarafından Skip Montanaro's avatar Skip Montanaro

Clarify the difference between text and binary files. I'm not sure the

tutorial is the right place to mention a file object's encoding.
üst 5dde61d0
...@@ -197,14 +197,20 @@ automatically added to the end. ``'r+'`` opens the file for both reading and ...@@ -197,14 +197,20 @@ automatically added to the end. ``'r+'`` opens the file for both reading and
writing. The *mode* argument is optional; ``'r'`` will be assumed if it's writing. The *mode* argument is optional; ``'r'`` will be assumed if it's
omitted. omitted.
On Windows and the Macintosh, ``'b'`` appended to the mode opens the file in ``'b'`` appended to the mode opens the file in binary mode, so there are
binary mode, so there are also modes like ``'rb'``, ``'wb'``, and ``'r+b'``. also modes like ``'rb'``, ``'wb'``, and ``'r+b'``. Python distinguishes
Windows makes a distinction between text and binary files; the end-of-line between text and binary files. Binary files are read and written without
characters in text files are automatically altered slightly when data is read or any data transformation. In text mode, platform-specific newline
written. This behind-the-scenes modification to file data is fine for ASCII representations are automatically converted to newlines when read and
text files, but it'll corrupt binary data like that in :file:`JPEG` or newline characters are automatically converted to the proper
:file:`EXE` files. Be very careful to use binary mode when reading and writing platform-specific representation when written. This makes writing portable
such files. code which reads or writes text files easier. In addition, when reading
from or writing to text files, the data are automatically decoded or
encoding, respectively, using the encoding associated with the file.
This behind-the-scenes modification to file data is fine for text files, but
will corrupt binary data like that in :file:`JPEG` or :file:`EXE` files. Be
very careful to use binary mode when reading and writing such files.
.. _tut-filemethods: .. _tut-filemethods:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment