string module

Fernando Pérez fperez528 at yahoo.com
Mon May 20 03:59:59 EDT 2002


Tim Peters wrote:

> A more relevant section in string.py is at its end:
> 
> try:
>     from strop import maketrans, lowercase, uppercase, whitespace
>     letters = lowercase + uppercase
> except ImportError:
>     pass

Well, that still doesn't answer my question. I modified that section to read:

try:
    from strop import maketrans, lowercase, uppercase, whitespace
    letters = lowercase + uppercase
    print 'strop'
except ImportError:
    print 'no strop'
    pass                                          # Use the original versions


Now, at the interactive python prompt:

[~]> python
Python 2.2 (#1, Feb 24 2002, 16:21:58)
[GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux-i386
Type "help", "copyright", "credits" or "license" for more information.
strop
>>> import string
>>> string.__file__
'/usr/lib/python2.2/string.py'
>>> print string.uppercase
ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞ
>>>


But running the following file:

import string
print string.__file__
print string.uppercase

I get:

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


Why the difference? They are both apparently importing the same thing, from 
the same code. I just don't get it.

Thanks for any enlightenment,

f.



More information about the Python-list mailing list