Hi, I want to set globale variables in external methods. With the following constuct I get errors if myFunctionA is set as function in the add external method form. Does anybody know how to set up global vars in external methods. -- many thanks for your replies, Elena #myExternalModul.py def myFunctionA(var1): global var1 myFunctionB() return def myFunctionB(): var2 = var1 return var2
On Thu, Dec 12, 2002 at 01:02:20PM +0100, Elena Schulz wrote:
Hi,
I want to set globale variables in external methods.
With the following constuct I get errors if myFunctionA is set as function in the add external method form. Does anybody know how to set up global vars in external methods.
-- many thanks for your replies, Elena
#myExternalModul.py
def myFunctionA(var1):
global var1
Stop right there... that's a syntax error in Python: SyntaxError: name 'var1' is local and global What are you really trying to do? Why do you pass a parameter to myFuntionA and then try to make the name of the parameter (which is local to the function by definition) a global? --PW -- Paul Winkler http://www.slinkp.com "Welcome to Muppet Labs, where the future is made - today!"
Elena Schulz writes:
I want to set globale variables in external methods. Don't!
The "module" namespace of external methods exists in copies for the different threads. If you set (global) variables in one thread, other threads will not see them. When you need (module) global variables, put them into a real Python module (or packages) not in the source of an External Method. The namespaces of such modules are shared by all threads. Depending on the use of the global variables, you must synchronize access to them by means of locks. Dieter
participants (3)
-
Dieter Maurer -
Elena Schulz -
Paul Winkler