Rasmus,
Make these couple of changes in the method 'import_module' and it should
work for most Python modules.
try:
if parent and parent.__path__:
fp, pathname, stuff = imp.find_module(partname, parent and
parent.__path__)
else:
fp, pathname, stuff = imp.find_module(partname)
except ImportError:
return None
try:
#m = imp.load_module(fqname, fp, pathname, stuff)
original_reload(sys.modules[partname])
m = sys.modules[partname]
finally:
if fp: fp.close()
There is a bug in the Jython version of imp.find_module where if the
second argument is None it does not use sys.path as documented in the
CPython documentation. That's the exception you saw.
Here's a trivial sample. If you have other issues, you might want to
contact the author.
a.py
****
class A:
def __init__(self):
print "a"
b.py
****
import a
class B(a.A):
def __init__(self):
a.A.__init__(self)
print "b"
Jython 2.1b1 on java1.3.0 (JIT: null)
Type "copyright", "credits" or "license" for more information.
>>> import a, b
>>> a.A()
a
<a.A instance at 3559141>
>>> b.B()
a
b
<b.B instance at 4515730>
>>> reload(b)
<module b at 1732618>
>>> b.B()
a
b
<b.B instance at 2147462>
>>> fp = open(r"d:/home/development/python/a.py", "r")
>>> data = fp.read()
>>> fp.close()
>>> data = data.replace('"a"', '"c"')
>>> fp = open(r"d:/home/development/python/a.py", "w")
>>> fp.write(data)
>>> fp.close()
>>> import deep_reload
>>> deep_reload.reload(b)
Reloading b
Reloading a
<module b at 1732618>
>>> b.B()
c
b
<b.B instance at 3115826>
>>>
brian
> -----Original Message-----
> From: jython-users-admin@...
> [mailto:jython-users-admin@...] On Behalf
> Of Rasmus Fogh
> Sent: Friday, December 14, 2001 4:36 AM
> To: brian zimmer
> Cc: jython-users@...
> Subject: RE: [Jython-users] reload command
>
>
> Thanks. deep_reload is very useful.
>
> Of course it does not work, as imp.find_module('test',None) throws
> AttributeError: __getitem__ when I run deep_reload from
> inside my Jython 2.0 ObjectDomain Jython interpreter, but I
> guess you cannot have everyting...
>
> Rasmus
>
> --------------------------------------------------------------
> -------------
> Dr. Rasmus H. Fogh Email: r.h.fogh@...
> Dept. of Biochemistry, University of Cambridge,
> 80 Tennis Court Road, Cambridge CB2 1GA, UK. FAX (01223)766002
>
> On Thu, 13 Dec 2001, brian zimmer wrote:
>
> > Rasmus,
> >
> > Python's reload() does not work recursively, but this replacement
> > does:
> >
> > http://www.idyll.org/~n8gray/code/files/deep_reload.py
> >
> > brian
> >
>
>
> _______________________________________________
> Jython-users mailing list
> Jython-users@...
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
|