[ python-Bugs-935749 ] locale dependency of string methods
undocumented
SourceForge.net
noreply at sourceforge.net
Thu Apr 15 12:26:34 EDT 2004
Bugs item #935749, was opened at 2004-04-16 01:26
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=935749&group_id=5470
Category: Documentation
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: George Yoshida (quiver)
Assigned to: Nobody/Anonymous (nobody)
Summary: locale dependency of string methods undocumented
Initial Comment:
Some string methods/constants are locale dependent,
but unlike string constants, string methods lack the
description about the locale dependency.
This wasn't a big problem in older Python, but since
Python 2.3 each time when you start up an IDLE,
lib/idlelib/IOBinding.py sets the locale to LC_CTYPE:
locale.setlocale(locale.LC_CTYPE, "")
This affects the behavior of string methods and module
(at least on Windows when locale is set to
('Japanese_Japan', 'cp932')).
Here is the result of locale-dependent
constants/methods.
IDLE 1.0.2 # IDLE on Windows 2000
>>> import string, locale
>>> string.letters
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv
wxyz\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1
\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9
\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6
\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3
\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf'
>>> _[-1].isalpha()
True
>>> locale.getlocale()
['Japanese_Japan', '932']
This *feature* can be easily reproduced from the
command line.
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC
v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> import string, locale
>>> string.letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV
WXYZ'
>>> locale.getlocale()
(None, None)
>>> locale.setlocale(locale.LC_CTYPE, '')
'Japanese_Japan.932'
>>> string.letters
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv
wxyz\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1
\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9
\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6
\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3
\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf'
>>> _[-1].isalnum()
True
Quote from msdn.microsoft.com:
* http://msdn.microsoft.com/library/en-
us/vclib/html/_crt_isalpha.2c_.iswalpha.asp
The result of the test condition for the isalpha function
depends on the LC_CTYPE category setting of the
current locale; see setlocale for more information.
string methods affected are:
* isalpha
* isalpnum
MS also says that some other string methods(islower,
isdigit, etc.) are locale dependent, so it might be
betterto add a note about the dependency to those
methods too.
Thanks.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=935749&group_id=5470
More information about the Python-bugs-list
mailing list