Nested function scope problem
Steve Holden
steve at holdenweb.com
Mon Jul 24 16:09:24 EDT 2006
danielx wrote:
> Gerhard Fiedler wrote:
[...]
>>Yes, but it is the line "tok = ''" that seems to cause tok to be now a
>>variable of the inner function's scope (rather than the variable tok of
>>breakLine).
>
>
> OHH! Yes, that sounds like it could be it. Wow, to me, that behavior is
> eXtremely unexpected (there's lisp popping up its ugly head again :P).
> So you're saying that because an assignment to tok appears later within
> the def for addTok, that the line if len(tok) won't try to look in
> enclosing local scopes? (If such things even exist...)
>
> Gerhard's reply sounded not so confident. Can we have someone who
> "really" knows weigh in on this? Thanks!
>
Would I do? If there's a binding to a name *anywhere* in the function's
body then that name is treated as local to the function. This is a
matter of static analysis, and is irrespective of where in the body the
assignment is found.
Of course, you could always test this yourself in interactive mode ...
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list