fully-qualified namespaces?

Michael Hoffman cam.ac.uk at mh391.invalid
Mon Sep 12 18:51:56 CEST 2005

Lenny G. wrote:

> Hippo/
>   __init__.py
>   Crypto.py
>   Potamus.py
> And inside Crypto.py, I need to access python-crypto's Crypto.Hash
> package.  Inside Potamus.py, I need to access Hippo.Crypto, e.g.,
> Hippo/
>   __init__.py
>   Crypto.py        # wants to import python-crypto's Crypto.Hash
>   Potamus.py       # wants to import Hippo's Crypto
> Can I do this?  Crypto.py can't seem to access python-crypto's Crypto
> namespace, because it's own namespace takes precendence.  I tried using
> the renaming trick inside of Crypto.py, but it still can't find the
> original python-crypto Crypto.  Maybe there's something I can do in the
> __init__.py?  Maybe something with __path__?  Is there a better way to
> access namespaces from the module files themselves?

The *best* way would surely be to rename Hippo/Crypto.py to something 
else. This will save you some grief.

If you wanted to load based on filenames, you can use the imp module in 
the stdlib.
Michael Hoffman

More information about the Python-list mailing list