[mod_python] Multiple handler question

Daniel West dwmp at opti.cgi.net
Thu Jan 15 22:31:55 EST 2004


At 08:16 PM 1/15/2004 -0800, you wrote:
>Hi, All.
>
>I've been playing with mod_python for a little while, and I love it! I
>do have one puzzle, though.
>
>What would be the best way of executing an on-disk module? It would be
>nice to be able to do  something like:
>
>def handler(req):
>     modname = req.filename
>     if modname.endswith('.pyx'):
>         import modname
>         modname['main'](req)
>
>(I know this is very pseudo. It's just to convey what I mean.)
>
>But as far as I know, you can't use 'import' on a variable.

How about the import builtin?

def handler(req):
     modname = req.filename
     if modname.endswith('.pyx'):
         mod = __import__(modname)
         mod.main(req)


Although it's a little more complicated than this.  You'll have to add the 
path to sys.path and then split out the file name to import.  Also you 
might have to do something to get python to import a file with a pyx extension.

-Dan



More information about the Mod_python mailing list