Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 349a3d3

Browse files
committed
Marc-Andre Lemburg <[email protected]>:
Made codecs.open() default to 'rb' as file mode.
1 parent d468bd3 commit 349a3d3

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/codecs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def __getattr__(self,name,
458458

459459
### Shortcuts
460460

461-
def open(filename, mode, encoding=None, errors='strict', buffering=1):
461+
def open(filename, mode='rb', encoding=None, errors='strict', buffering=1):
462462

463463
""" Open an encoded file using the given mode and return
464464
a wrapped version providing transparent encoding/decoding.
@@ -468,6 +468,11 @@ def open(filename, mode, encoding=None, errors='strict', buffering=1):
468468
codecs. Output is also codec dependent and will usually by
469469
Unicode as well.
470470
471+
Files are always opened in binary mode, even if no binary mode
472+
was specified. Thisis done to avoid data loss due to encodings
473+
using 8-bit values. The default file mode is 'rb' meaning to
474+
open the file in binary read mode.
475+
471476
encoding specifies the encoding which is to be used for the
472477
the file.
473478

0 commit comments

Comments
 (0)