[mod_python] PyhtonImport

Nicolas Lehuen nicolas.lehuen at gmail.com
Fri Oct 14 15:41:16 EDT 2005


Hi Paul,

PythonImport makes sure that the module is imported when the interpreter is
started. So you'll find it in sys.module. However, to see it amongst your
module's global variables, you need it import it in your module. This is
exactly the same in a standard Python interpreter : it's not because a
module has been imported by a module that it is present in all the other
modules' global variables.

So your published module should be :

import my_test

def t(req):
return globals()

Note two things :

1) I've renamed test to my_test, because test is a standard Python module
and trouble may ensue if you use this module name.
2) str() around globals is not needed IIRC. The publisher will apply it. But
that's a detail.

Regards,
Nicolas

2005/10/14, Paul Hide <paul.hide at gmail.com>:
>
> Server is: Apache 2.0.54, mod_python 3.1.3 Debian 3.1
> Client is Firefox 1.0.7 on ms win 2k
> The following file is successfully imported by a PythonImport directive.
>
> #PythonImport test
>
> from mod_python import apache
>
> apache.log_error('q8 q8 q8 q8')
>
> I know this because it writes to the error log.
>
> The directive that loads it is:
>
> PythonImport pyimp localhost.localdomain
>
> I know that my publisher programs are being run in this interpreter
> because:
>
> def t(req):
> return str(req.interpreter) #probably is a string anyway
>
> returns localhost.localdomain into my browser.
>
> If I now change my publisher program to say:
>
> def t(req):
> return str(globals()) #probably is a string anyway
>
> then why can't I see any reference to pyimp in the resulting output?
>
>
> Paul Hide
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20051014/483ad065/attachment.html


More information about the Mod_python mailing list