gh-85204: Improve locale.setlocale example (#132683)

This commit is contained in:
Stan Ulbrych 2025-12-16 11:26:33 +00:00 committed by GitHub
parent 58027999bf
commit c24e238417
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,8 +48,19 @@ The :mod:`locale` module defines the following exception and functions:
If *locale* is omitted or ``None``, the current setting for *category* is
returned.
Example::
>>> import locale
>>> loc = locale.setlocale(locale.LC_ALL) # get current locale
# use German locale; name and availability varies with platform
>>> locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
>>> 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
:func:`setlocale` is not thread-safe on most systems. Applications typically
start with a call of ::
start with a call of::
import locale
locale.setlocale(locale.LC_ALL, '')
@ -580,18 +591,6 @@ The :mod:`locale` module defines the following exception and functions:
:func:`localeconv`.
Example::
>>> 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
Background, details, hints, tips and caveats
--------------------------------------------