473,804 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_func tion()

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 1563
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_VARIAB LE'] = 'myvalue'

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

"jcj" <jc*******@bigf oot.com> wrote in message news:45******** *************** ***@posting.goo gle.com...
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_func tion()

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*****@hotmai l.com> wrote in message news:<Qp******* **********@twis ter.southeast.r r.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
1183
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. While function-level, module-level and "builtin-level" variables are still needed, I suggest a few different lookup schemes, with different levels of extremity:
0
1365
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. Globally, I'd like to do 2 things. The first, when I'm in the program, I call a script, which call a function
7
1078
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. Couldn't I put the variable in the usercontrol and somehow set it so that it can be used by usercontrol and all the forms? If so, how?
8
3731
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 script? Basically, can I have the following: #root.py import some_module.py some_module.afunction() # <== create a variable x1=1 and add it to the
8
8098
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
35252
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 the sake of brevity I am sticking to common usage. Wherever the term procedure is used in this tutorial it actually refers to a subroutine or function. Definition of Scope The scope of a variable where this variable can be seen or accessed...
2
2000
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 w.py", I got: 000=======Hello World 001=======Hello World 002=======Not Initialized 003=======Not Initialized 004=======Not Initialized
10
3018
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 the text and clicking a standard "submit" button. MAIN PROBLEM: My problem is that the information transmitted to the formhandler apparently has some sort of whitespace added to it. If I simply use trim() on the POST variable, it fails the...
3
2120
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, basically -g option enabled in all Makefile, there is a separate line ion each Makefile for CFLAGS, but at the root, I have single build_all script which calls each build script to compile each module and create each shared lib. can I pass this CFLAGS...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10354
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9177
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3005
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.