variable to be transmitted from a CGI script to a module

jcj jcjouffre at bigfoot.com
Thu Sep 18 05:25:23 EDT 2003


hello,
is it possible to have something like :

script.cgi
#!/usr/local/bin/python
# -*-python-*-
global MY_VARIABLE
MY_VARIABLE = "myvalue"
import module1
module1.my_function()

module1.py
# -*-python-*-
global MY_VARIABLE
if MY_VARIABLE:
   print 'variable defined'
else:
   print 'variable NOT defined'
def my_function():
   print 'my_function'

when I try to compile the module, I obtain this message :
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "module1.py", line 3, in ?
    if MY_VARIABLE:
NameError: global name 'MY_VARIABLE' is not defined

same error when executing the python CGI script

thanks in advance

Jean-Claude




More information about the Python-list mailing list