Packages, modules and exceptions

Ng Pheng Siong ngps at madcap.dyndns.org
Mon Mar 12 10:14:52 EST 2001


Hi,

In M2Crypto, I have the following (abridged) directory structure:

    M2Crypto/
            SSL/
                __init__.py
                Connection.py

Within M2Crypto/SSL/__init__.py, I have the following:

    class SSLError(Exception): pass


Now, various parts of M2Crypto/SSL/Connection.py wish to raise SSLError 
when it is appropriate to do so. 

For M2Crypto/SSL/Connection.py to get access to SSLError which is defined
in M2Crypto/SSL/__init__.py, it (Connection.py) contains the following:

    SSLError = 
     __import__('M2Crypto.SSL', globals(), locals(), 'SSLError').SSLError

This works, but looks kinda funny.

An equivalent(?) is:

    SSLError = 
     getattr('M2Crypto.SSL', globals(), locals(), 'SSLError'), 'SSLError')

Better, but still doesn't look very nice.

What's the best way to do this?

TIA for any input. Cheers.


-- 
Ng Pheng Siong <ngps at post1.com> * http://www.post1.com/home/ngps




More information about the Python-list mailing list