Packages, modules and exceptions
Steve Purcell
stephen_purcell at yahoo.com
Wed Mar 14 12:20:27 EST 2001
Ng Pheng Siong wrote:
> Within M2Crypto/SSL/Connection.py, I have "class Connection:..." Then,
> within M2Crypto/SSL/__init__.py, I have "from Connection import
> Connection". This is so that clients can say "s = M2Crypto.SSL.Connection()"
> instead of "s = M2Crypto.SSL.Connection.Connection()".
>
> Because of this, I can't just do "from M2Crypto.SSL import SSLError"
> within Connection.py. __init__.py's "from Connection import Connection"
> creates a circular reference.
You can. There is no problem with such a circular reference. Just try it out.
Consider the following files and their contents:
./M2Crypto/SSL/Connection.py
#---------
from M2Crypto.SSL import SSLError
class Connection:
pass
#---------
./M2Crypto/SSL/__init__.py
#---------
class SSLError(Exception):
pass
from Connection import Connection
#---------
./M2Crypto/__init__.py
#---------
#---------
I can start Python, and everything works as intended:
>>> from M2Crypto.SSL import Connection
>>> Connection
<class M2Crypto.SSL.Connection.Connection at 807f408>
Magic!
-Steve
--
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo
More information about the Python-list
mailing list