Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue47187

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:locale module example is wrong for some platforms
Type:Stage:
Components:DocumentationVersions:Python 3.10
process
Status:openResolution:
Dependencies:Superseder:
Assigned To: docs@pythonNosy List: docs@python, smarie
Priority:normalKeywords:

Created on2022-04-01 13:45 bysmarie, last changed2022-04-11 14:59 byadmin.

Messages (1)
msg416487 -(view)Author: Sylvain Marie (smarie)*Date: 2022-04-01 13:45
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 athttps://github.com/pandas-dev/pandas/issues/46595
History
DateUserActionArgs
2022-04-11 14:59:57adminsetgithub: 91343
2022-04-01 13:45:07smariecreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp