[mod_python] apache.import_module()

Colin Fox cfox at cfconsulting.ca
Wed Mar 17 23:11:08 EST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi, all.

I'm still struggling a bit to get all the nuances of my program working.

I'll eventually be opening this up as a GPL project, but at the moment
I'd kind of like to solidify it in my head before I do that. I know that
it would probably help to be able to point to the in-progress code so
that it could be viewed in context. Hopefully that will be soon.

Part of what I need is the ability to import modules on an ad-hoc basis.

What would be absolutely perfect would be the ability to do this:


- -------------
mymod.py:

# This module is found in subs/funstuff"
def func(req,arg):
~    req.write(arg)
- -------------

Then in my handler, I have this snippet:

- ---------------
m = 'mymod'
f = 'func'
p = 'subs/funstuff'

~    md = apache.import_module(m,path=p)
~    s = md[f](req,a)
- --------------

If I try this, I get:

~    ImportError: No frozen submodule named subs/funstuff.mymod

If I don't have the path, I just get:

~    ImportError: No module named mymod

How exactly is the path supposed to work? Is it supposed to be based off
of the current directory? The directory found in the url? What is a
frozen submodule?

And even if I was able to actually do the module import, can I use the
dictionary syntax for function execution? (md[f])?

Thanks,
~  cf


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAWUuMoaQ1/feGlJoRAreiAJ0ZYH/yaroeX8mgYtrQjBCCzCRpKgCfWpes
eFcu3yp2kx/yqZCUu4pvwSM=
=G+LZ
-----END PGP SIGNATURE-----


More information about the Mod_python mailing list