amit
amit at digitalpeers.com
Mon Jun 20 18:59:07 EDT 2005
Hello Grisha, def main(): req.write('Hello there!') if __name__=='__main__': import test_mod # test_mod.py is the name of the script ret = test_mod.main() sys.exit(ret) Nothing happend. I guessed that __name__ under mod_python might behave differently so I changed the '==' to '!=' and got the following traceback: Mod_python error: "PythonHandler pythonframe" Traceback (most recent call last): File "F:\Python23\Lib\site-packages\mod_python\apache.py", line 299, in HandlerDispatch result = object(req) File "C:/Program Files/Apache Group/Apache2/cgi-bin/mod_python/\pythonframe.py", line 91, in handler execfile(req.filename, {'req':req}) File "C:/Program Files/Apache Group/Apache2/cgi-bin/mod_python/test_mod.py", line 6, in ? ret = test_mod.main() File "C:/Program Files/Apache Group/Apache2/cgi-bin/mod_python/\test_mod.py", line 2, in main req.write('Hello there!') NameError: global name 'req' is not defined Amit I tried using the usual method to call main() Gregory (Grisha) Trubetskoy wrote: > > What calls the main() function below? > > Grisha > > > On Mon, 20 Jun 2005, amit wrote: > >> Hello, >> >> I am using mod_pyton to write a collection of scripts. And I am >> facing the following problem: >> I use the handler to execute a script. And I try to pass the req >> object to it: >> >> def handler(req): >> execfile(req.filename, {'req':req}) >> >> in the script I have the following code: >> >> def main(): >> req.write('Hello there!') >> >> I know that the script is executed but I don't get the 'hello there!' >> message in my browser. Can anyone help? >> >> Thanks >> Amit >> >> _______________________________________________ >> Mod_python mailing list >> Mod_python at modpython.org >> http://mailman.modpython.org/mailman/listinfo/mod_python >> > >
|