Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8d2ef87

Browse files
committed
Update what the locale module documents about string operations.
1 parent 00bc0e0 commit 8d2ef87

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

Doc/library/locale.rst

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -498,26 +498,23 @@ is almost as bad: it is expensive and affects other threads that happen to run
498498
before the settings have been restored.
499499

500500
If, when coding a module for general use, you need a locale independent version
501-
of an operation that is affected by the locale (such as :func:`string.lower`, or
501+
of an operation that is affected by the locale (such as
502502
certain formats used with :func:`time.strftime`), you will have to find a way to
503503
do it without using the standard library routine. Even better is convincing
504504
yourself that using locale settings is okay. Only as a last resort should you
505505
document that your module is not compatible with non-\ ``C`` locale settings.
506506

507-
.. index:: module: string
508-
509-
The case conversion functions in the :mod:`string` module are affected by the
510-
locale settings. When a call to the :func:`setlocale` function changes the
511-
:const:`LC_CTYPE` settings, the variables ``string.lowercase``,
512-
``string.uppercase`` and ``string.letters`` are recalculated. Note that code
513-
that uses these variable through ':keyword:`from` ... :keyword:`import` ...',
514-
e.g. ``from string import letters``, is not affected by subsequent
515-
:func:`setlocale` calls.
516-
517507
The only way to perform numeric operations according to the locale is to use the
518508
special functions defined by this module: :func:`atof`, :func:`atoi`,
519509
:func:`format`, :func:`str`.
520510

511+
There is no way to perform case conversions and character classifications
512+
according to the locale. For (Unicode) text strings these are done according
513+
to the character value only, while for byte strings, the conversions and
514+
classifications are done according to the ASCII value of the byte, and bytes
515+
whose high bit is set (i.e., non-ASCII bytes) are never converted or considered
516+
part of a character class such as letter or whitespace.
517+
521518

522519
.. _embedding-locale:
523520

0 commit comments

Comments
 (0)