[New-bugs-announce] [issue43140] build-in open() doesn't use whatever locale.getpreferredencoding() returns as default encoding.

Cake Xu report at bugs.python.org
Sat Feb 6 00:16:14 EST 2021


New submission from Cake Xu <smallbigcake at qq.com>:

In the document about build-in function open() https://docs.python.org/3/library/functions.html#open, it says that
"encoding is the name of the encoding used to decode or encode the file. This should only be used in text mode. The default encoding is platform dependent (whatever locale.getpreferredencoding() returns), but any text encoding supported by Python can be used. See the codecs module for the list of supported encodings.
"
But as I tried, I found that after I set locale using locale.setlocale(), the default encoding used by open() was changed and thus sometimes led to a UnicodeDecodeError.

So I think that the default encoding used by open() is the second element of whatever locale returned by locale.getlocale().

----------
assignee: docs at python
components: Documentation
messages: 386544
nosy: docs at python, smallbigcake
priority: normal
severity: normal
status: open
title: build-in open() doesn't use whatever locale.getpreferredencoding() returns as default encoding.
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43140>
_______________________________________


More information about the New-bugs-announce mailing list