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

Michael Hudson mwh at python.net
Fri Oct 10 12:32:35 EDT 2003


"Edward K. Ream" <edreamleo at charter.net> writes:

> 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. 

Must be because you weren't looking <wink>:

Python 2.2.1 (#1, Apr  9 2002, 13:10:27) 
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> u'a' in string.letters
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeError: ASCII decoding error: ordinal not in range(128)

(python from Sean's 2.2.1 RPM on redhat 7.2-ish).

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

What you may be missing is that factors including but not limited to
readline, the way python was invoked, orders of imports, locals
settings and the phase of the moon may have an effect on whether
"ordinals not in range(128)" get into string.letters.

I think the interaction of readline and locale settings got a going
over for 2.3 which *might* explain any differences you're seeing.

> 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.

See above :-)

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

Err, probably.  Depends what you're testing for, I guess.  Wouldn't
uch.isalpha() or one of the unicodedata thingies be more appropriate
most of the time?

Cheers,
mwh

PS: on typing control-D into the 2.2.1 session above, I get a
    segfault.  Now *that's* got to be a bug!

-- 
  surely, somewhere, somehow, in the history of computing, at least
  one manual has been written that you could at least remotely
  attempt to consider possibly glancing at.              -- Adam Rixey




More information about the Python-list mailing list