Xiang Zhang <angwe...@126.com> added the comment: I don't understand Josh. Looking from the code only when *passing* encoding binary mode is forced, although in the comment it's saying always.
>>> f = codecs.open('/tmp/a', 'w') >>> f <open file '/tmp/a', mode 'w' at 0x7f516efbb6f0> For example I want to use 'replace' instead of 'strict' for default encoding, I can't simply do: >>> import codecs >>> f = codecs.open('/tmp/a', 'w', errors='replace') >>> f.write(u'\udc80') Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\udc80' in position 0: ordinal not in range(128) I have to specify the default encoding explicitly to make errors function: >>> f = codecs.open('/tmp/a', 'w', encoding='ascii', errors='replace') >>> f.write(u'\udc80') ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32723> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com