473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 1549
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 rules are ancient remnants of a different Python. ...
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 found no answer. So I ask you directly. ...
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 be used by the control and all the forms. ...
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 module add variables to the scope of the calling...
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 basics of variable scope in VBA for MS Access. For...
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 declared. See the code below. When I run "python...
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. The user can update the information by modifying...
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. Each of this Makefile had CFLAGS defined inside,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.