472,351 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 software developers and data experts.

variable to be transmitted from a CGI script to a module

jcj
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
Jul 18 '05 #1
3 1523
jcj
as the goal is to pass a parameter to a module, I found a way using
the OS environment :

in the cgi, I do like a putenv :
os.environ['MY_UNIX_VARIABLE'] = 'myvalue'

in the module, I do like a getenv :
MY_PYTHON_VARIABLE = os.environ['MY_UNIX_VARIABLE']
Jul 18 '05 #2
Read also the thread "How to pass parameter to a module?"
M-a-S

"jcj" <jc*******@bigfoot.com> wrote in message news:45**************************@posting.google.c om...
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'
Jean-Claude

Jul 18 '05 #3
jcj
"M-a-S" <NO*****@hotmail.com> wrote in message news:<Qp*****************@twister.southeast.rr.com >...
Read also the thread "How to pass parameter to a module?"
M-a-S


you're right, the proper solution is :

import sys
print sys.modules['__main__'].myVariable

thanks a lot
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eyal Lotem | last post by:
Python has a few issues many consider problems with regard to its variable namespacing. It seems that the local/global/builtins namespacing...
0
by: Mike | last post by:
Hello All, I'm working ( and a beginner ) with mixing Python scripting and C++. And I need some little help. :) I've searched on the net, but...
7
by: Just Me | last post by:
I have a project that contains a usercontrol, some forms and a module. The only thing in the module is one variable that is there so that it can...
8
by: MakaMaka | last post by:
Hi, I have a scope related question that I haven't been able to find an answer to anywhere. Is there a way to have a function in an imported...
8
by: yinglcs | last post by:
Hi, I have the following code: colorIndex = 0; def test(): print colorIndex; This won't work. But it works if i do this:
0
MMcCarthy
by: MMcCarthy | last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the...
2
by: Bruza | last post by:
I am trying to define a class static variable. But the value of the static variable seems to be only defined inside the file that the class is...
10
by: Mason Barge | last post by:
I have a standard POST form consisting of two types of input: text input and textarea. The form downloads current settings from a mysql database. ...
3
by: tvnaidu | last post by:
Currently I have 15 module folders, each module had C code, also Makefile in each folder, also build script to create shared lib for each module....
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.