Automatic reload()?
Alex
cut_me_out at hotmail.com
Sat Jun 3 18:10:26 EDT 2000
> I have this in my ~/.pythonrc:
>
> def rr(keepem=sys.modules.keys()):
> for i in sys.modules.keys():
> if type(sys.modules[i]) is types.ModuleType and i not in keepem:
> print "reloading",i
> reload(sys.modules[i])
>
That could cause some confusing problems if you're unlucky about the
order the modules get loaded in. E.g.:
A.py:
######################################################################
import B, C
reload (B)
reload (C)
t = B.B ()
B.py:
######################################################################
import C
class B (C.C):
def __init__ (self):
C.C.__init__ (self)
C.py:
######################################################################
class C:
def __init__ (self):
pass
% python A.py
Traceback (innermost last):
File "A.py", line 5, in ?
t = B.B ()
File "B.py", line 6, in __init__
C.C.__init__ (self)
TypeError: unbound method must be called with class instance 1st argument
The problem is, the C.C which B becomes a subclass of is the version
from before the reload, but the C.C in C.C.__init__ refers to the
version following the reload.
Alex.
More information about the Python-list
mailing list