string module

Fernando Pérez fperez528 at yahoo.com
Mon May 20 01:51:08 EDT 2002


Fernando Pérez wrote:

>> For example, string.uppercase has the following values:
>> 
>> ABCDEFGHIJKLMNOPQRSTUVWXYZ\xC0\xC1\xC2....\xCde
>> 
> 
>>>> import string
>>>> string.uppercase
> 
'ABCDEFGHIJKLMNOPQRSTUVWXYZ\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xde'
>>>> print string.uppercase
> ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ
> 

But now I'm totally confused. The above works at a python prompt, but the 
simple program
 
import string
print string.__file__
print string.uppercase

executed at the system prompt gives:

[~]> python t.py
/usr/lib/python2.2/string.pyc
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Huh??? How can the python shell get a different value? I checked in the 
interactive prompt and string.__file__ does point to the same file as 
indicated above. So how in the world do I get the extra accented chars shoved 
into string.uppercase? The relevant section in /usr/lib/python2.2/string.py:

# Some strings for ctype-style character classification
whitespace = ' \t\n\r\v\f'
lowercase = 'abcdefghijklmnopqrstuvwxyz'
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
letters = lowercase + uppercase

I'd very much appreciate someone who could explain who is putting the extra 
chars into these module constants when at the python prompt.

Cheers,

f.



More information about the Python-list mailing list