You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
locale module example is wrong for some platforms #91343
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2022-04-01.13:45:07.191>labels= ['3.10', 'docs']
title='locale module example is wrong for some platforms'updated_at=<Date2022-04-01.13:45:07.191>user='https://github.com/smarie'
>>>importlocale>>>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
Activity
smarie commentedon Apr 1, 2022
The example in the doc shows
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
Note: this issue was first reported in the
pandaslibrary at pandas-dev/pandas#46595StanFromIreland commentedon Mar 23, 2025
Duplicate of: #85204