Importing dynamically loaded modules (in packages)?

Irmen de Jong irmen at NOSPAMREMOVETHISxs4all.nl
Tue Apr 30 21:30:16 EDT 2002


"holger krekel" <pyth at devel.trillke.net> wrote in message
news:mailman.1020213066.536.python-list at python.org...

> > "import Package.TestModule" still doesn't work: ""no module named
TestModule""
> > How can I correct this?
>
>     sys.modules['Package.TestModule'] = TestModule
>
> after that you should be able to do
>
>     import Package.TestModule

Ouch... isn't that cheating? I mean, the Module name is "TestModule",
not "Package.TestModule".
Anyway I've tried
    import test.pystone
and sys.modules.keys() indeed contains not only "test" but also "test.pystone".
So my guess is, for module "a.b.c.m" we need to add
"a", "a.b", "a.b.c", "a.b.c.m" (etc) to sys.modules.
I still find this a bit weird, but if it works, who cares.

I'll have to try this. Thanks.

Irmen




More information about the Python-list mailing list