This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author smarie
Recipients docs@python, smarie
Date 2022-04-01.13:45:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1648820707.2.0.705668784444.issue47187@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2022-04-01 13:45:07smariesetrecipients: + smarie, docs@python
2022-04-01 13:45:07smariesetmessageid: <1648820707.2.0.705668784444.issue47187@roundup.psfhosted.org>
2022-04-01 13:45:07smarielinkissue47187 messages
2022-04-01 13:45:07smariecreate