[issue47187] locale module example is wrong for some platforms
1 Apr
2022
1 Apr
'22
8:45 a.m.
New submission from Sylvain Marie <sylvain.marie@schneider-electric.com>: The example in the doc shows ```python
import locale loc = locale.getlocale() # get current locale # use German locale; name might vary with platform locale.setlocale(locale.LC_ALL, 'de_DE') locale.strcoll('f\xe4n', 'foo') # compare a string containing an umlaut locale.setlocale(locale.LC_ALL, '') # use user's preferred locale locale.setlocale(locale.LC_ALL, 'C') # use default (C) locale locale.setlocale(locale.LC_ALL, loc) # restore saved locale
However locale.getlocale() does not return the locale for all categories (locale.LC_ALL is even not allowed) but the locale for the LC_CTYPE category.
Therefore restoring it using `locale.setlocale(locale.LC_ALL, loc)` does not actually restore the initial settings, and may even fail on some platforms (on mine it does).
The correct example should have the first line of code replaced with
loc = locale.setlocale(locale.LC_ALL) # get current locale
Note: this issue was first reported in the `pandas` library at https://github.com/pandas-dev/pandas/issues/46595
----------
assignee: docs@python
components: Documentation
messages: 416487
nosy: docs@python, smarie
priority: normal
severity: normal
status: open
title: locale module example is wrong for some platforms
versions: Python 3.10
_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue47187>
_______________________________________
944
Age (days ago)
944
Last active (days ago)
0 comments
1 participants
participants (1)
-
Sylvain Marie