Re: Variables in nested functions

2006-08-30 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: Is it possible to change the value of a variable in the outer function if you are in a nested inner function? Depends on what you mean by changing the value. If you mean mutating a mutable object, yes, it's possible. If you mean rebinding the name to a different object,

Re: Variables in nested functions

2006-08-30 Thread Bryan Olson
Ben Cartwright wrote: The typical kludge is to wrap the variable in the outer function inside a mutable object, then pass it into the inner using a default argument: def outer(): a = outer def inner(wrapa=[a]): print wrapa[0] wrapa[0] = inner return inner As

Variables in nested functions

2006-08-29 Thread zero . maximum
Is it possible to change the value of a variable in the outer function if you are in a nested inner function? For example: def outer(): a = outer def inner(): print a a = inner # I'm trying to change the outer 'a' here, # but this

Re: Variables in nested functions

2006-08-29 Thread Ben Cartwright
[EMAIL PROTECTED] wrote: Is it possible to change the value of a variable in the outer function if you are in a nested inner function? The typical kludge is to wrap the variable in the outer function inside a mutable object, then pass it into the inner using a default argument: def outer():