[Tutor] variable scope in nested functions

2005-04-25 Thread Logesh Pillay
Thanks Kent for your reply. You said This is a limitation of Python's nested scopes. You can't assign to a variable in an enclosing scope. One way to work around this is to use a mutable value like a list in the enclosing scope: def foo (n): counter = [0] def choose (i): if (solution

[Tutor] variable scope in nested functions

2005-04-24 Thread Logesh Pillay
Hello list I am having trouble with a variable to act as a counter in a nested recursive function which will only occasionally find an answer. Something like a static variable in C. Why does this sort of thing not work? def foo (n): counter = 0 def choose (i): if (solution found):

Re: [Tutor] variable scope in nested functions

2005-04-24 Thread Kent Johnson
Logesh Pillay wrote: Hello list I am having trouble with a variable to act as a counter in a nested recursive function which will only occasionally find an answer. Something like a static variable in C. Why does this sort of thing not work? def foo (n): counter = 0 def choose (i):