Message389068
On 19.03.2021 11:36, STINNER Victor wrote:
>
> STINNER Victor <vstinner@python.org> added the comment:
>
>> locale.getencoding()
>>
>> which interfaces to nl_langinfo(CODESET) or the Windows code
>> page and does not try to do any magic, ie. does *not* call
>> setlocale(). It needs to return what the lib C currently
>> knows and uses as encoding.
>
> This is locale.get_current_locale_encoding(). I would like to put "current" in the name, because there is a lot of confusion between get_current_locale_encoding() encoding and locale.getpreferredencoding(False) encoding. In locale.getpreferredencoding(False), Python ignores the locale in some cases which is counter intuitive.
These attempts have resulted much of the confusion around the locale
module. It's better not to create more of it.
- "locale" in the name is unnecessary, since this is the locale module.
- If you add "current", people will rightly ask: then what do all the
other APIs in the locale module return ? Of course, they all return
the current state of settings :-) So this is unnecessary as well.
locale.getencoding() works in the same way as locale.getlocale().
It interfaces to the lib C and returns the current encoding setting
as known by the lib C. It's just a more intuitive name than
locale.nl_langinfo(CODESET) and works on Windows as well.
And, again, locale.getpreferredencoding() should be deprecated.
The API has been misused in too many ways and is completely broken
by now. It was a good idea at the time, when Martin added it,
even though I never liked the name. |
|
Date |
User |
Action |
Args |
2021-03-19 10:59:43 | lemburg | set | recipients:
+ lemburg, vstinner |
2021-03-19 10:59:43 | lemburg | link | issue43552 messages |
2021-03-19 10:59:43 | lemburg | create | |
|