Trouble with nested scopes when trying to rebind a variable

Fernando Rodriguez frr at easyjob.net
Fri Nov 21 09:16:36 EST 2003


Hi,

I have a parameter defined in a module, called PREVIEW.  Many functions use
it's value to modify their behavior.

A function called dispatch checks the user arguments in sys.argv and calls the
appropriate function. It should also modify the value of PREVIEW depending on
the user input.

And here's where I get into trouble:  if I write something like PREVIEW = None
inside the body of a function, it doesn't modify the value of the existing
PREVIEW variable, it creates a new variable in the function scope.

How can I modify the external PREVIEW variable?

In Lisp there are different operators to rebind an existing variable and to
create a new variable.  How do you do this in python?




More information about the Python-list mailing list