[Gerry]
>HI,
>I have successfully used CPython's imp.load_module() in the past to load
>Python code on the fly. This has been invaluable for lots of reasons
>including the ability to introduce modules dynamically into a running system.
> The same code will not work with Jython because Jython lacks the
>imp.load_module() method, and the comment for the module states that the
>methods implemented there are those that, in the writer's words, "can" be
>implemented under J(P)ython. Is this true?
It's true. At least until someone proves me wrong and submits a working
patch.
>I would appreciate any help in doing what the CPython load_module() provides
>under Jython. I'm sure that my lack of knowledge of Jython's import code is
>the problem - there's probably a solution so easy that I'm not even seeing
>it. The archives don't seem to have anything related. The import-sig
>postings haven't helped yet.
I have blissfully forgotten the finer details of imp.load_module() but
you can fake an import with code like this. It creates a module, inserts
it in sys.modules and execute some code in the module namespace.
moduletext = """
import sys
def foo():
print sys.path
"""
import sys, new
sys.modules['mymodule'] = mod = new.module("mymodule")
exec moduletext in mod.__dict__
regards,
finn
|