Just guessing, but your problem likely lies in A.Function1 (the one
that sets global variables):

python does something kinda tricky with namespaces and global
variables: if you refer to the name of a global variable inside a
function, and only READ from it, then the name is bound to the global
variable, and it reads the global value.  If, however, you ASSIGN to a
name which is the same as a global variable, then it actually creates
a new, local variable with the same name, and assigns to that - the
value stored in the global variable will not change.

To get around this, you need to explicitly declare the variable to to
be global in your function, like so:

# module A

myGlobal = "I'm not set!"

def setGlobal():
    global myGlobal     # bind myGlobal to the global A.myGlobal
    myGlobal = "I'm all set!"


# Just to illustrate...
def printGlobal():
    print myGlobal    # This will work, because we haven't done any assignment

On Tue, Apr 21, 2009 at 1:05 PM, sberger <[email protected]> wrote:
>
> I would like to create global variable so that I can access them in
> different modules. But It doesn't seem to work.
>
> What I need is this:
>
> module A
> define global var
>
> Function1
> set global var value
>
> Module B
> Function1
> read global var value
>
> When I do this, the global var is only accessible in the module A, i
> can't access it in module B, anyone know if this can be done?
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to