Nested function scope problem

Gerhard Fiedler gelists at gmail.com
Mon Jul 24 16:09:26 EDT 2006


On 2006-07-24 16:51:56, danielx wrote:

> Gerhard's reply sounded not so confident. 

Yes, it is not. It's just the conclusion I drew from my experiments. (I'm
still all wet behind the ears WRT Python...)

As long as there was no write access to the variable, the inner function
could read the value just fine. When there was a write access, the first
read (if it was before the write access) bombed with that error message
that there was a read without a previous write. (Actually, it wasn't a
simple read, it was that "len(var)" access. I'm not sure a normal read
would bomb the same way. But the error message was that it was a read
access without a previous write.)

So that was just my conclusion. It is also consistent with the observation
that variables seem to be known in their scope, even before the location of
their first appearance. 

> Can we have someone who "really" knows weigh in on this? 

That would be nice :)

Gerhard




More information about the Python-list mailing list