Strange variable scope... is this right?
Fredrik Lundh
fredrik at effbot.org
Thu Jan 18 01:41:28 EST 2001
Emile van Sebille wrote:
> Assuming that's correct then, is this piece of code with
> annotations the way that it's working?
>
> f = ["row", "cow", "arrow"]
> # create three element list object and bind to 'f'
> for f in f:
> # save reference to 'f' to iterate over,
> # re-binding 'f' to each in turn
> for f in range (len (f)):
> # save reference to newly created range object
> # of len (f)
> # re-binding 'f' to each in turn
>
> It feels like this is less an issue with namespaces and more
> an issue of how the for loop works.
>
> Am-I-getting-closer-ly y'rs,
cannot get much closer.
see http://www.python.org/doc/current/ref/for.html
for a formal description.
Cheers /F
More information about the Python-list
mailing list