u'a' in string.letters fails: a Python 2.3 bug?

Edward K. Ream edreamleo at charter.net
Fri Oct 10 18:03:00 CEST 2003


>From the documentation for the string module at:

C:\Python23\Doc\Python-Docs-2.3.1\lib\module-string.html

[quote]
letters: The concatenation of the strings lowercase and uppercase described
below. The specific value is locale-dependent, and will be updated when
locale.setlocale() is called.
[end quote]

If uch is a unicode character, the operation

uch in string.letters

may (will?) fail in Python 2.3. I've never seen it fail in previous
versions. Examples:

Python 2.3.1 (#47, Sep 23 2003, 23:47:32) [MSC v.1200 32 bit (Intel)] on
win32
[snip]
IDLE 1.0
>>> import string
>>> '\xa6' in string.digits
False
>>> '\xa6' in string.letters
False
>>> u'\xa6' in string.letters

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in -toplevel-
    u'\xa6' in string.letters
UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position 52:
ordinal not in range(128)
>>>u'\xa6' in string.ascii_letters
False
>>> u'a' in string.letters

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in -toplevel-
    u'a' in string.letters
UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position 52:
ordinal not in range(128)

Questions:

1. Is this a bug, or am I missing something?

2. Is this an issue only with Idle?  I think not completely: this kind of
code seems to work for my app on XP, and not for some of my app's users on
Linux.

3. Is replacing string.letters by string.ascii_letters the recommended
workaround?

Edward

P.S.

>>> string.letters
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\x83\x8a\x8c\x8e\x9a\x9
c\x9e\x9f\xaa\xb5\xba\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xc
d\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe
1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf
4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'

EKR
--------------------------------------------------------------------
Edward K. Ream   email:  edreamleo at charter.net
Leo: Literate Editor with Outlines
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------






More information about the Python-list mailing list