loop scope

Arthur ajsiegel at optonline.com
Mon Mar 15 09:43:20 EST 2004


>
>I think I may have misunderstood your original question.  The title of
>the thread is 'loop scope', but your question seems to be specifically
>on the loop iteration variable 't'.  Just think of it as a normal
>variable in the current local scope.

I can. But it's not my first inclination.  And I would speculate I am
far from alone. Having subtleties to be aware of in something as
fundamenatal as a for loop is not a great thing, IMO. On the hand
hand, it was a long time before any subtleties here had any practical
implications to me.  I had been getting away with ignorance.  But its
not a good feeling to know that.

t=None #(or something) 

required prior to a loop would  assure I am conscious of what I am
getting myself into.  Without it, it seems it isn't safe to assume the
user understands the full implications of simply complying with
required loop syntax.

Wouldn't something like this make sense:

With a loop iteration variable declared explicitly in the curent scope
and prior to the loop, it survives the loop.  Otherwise it is treated
as a placeholder within the loop, and goes out of scope at its
conclusion.

All other issues regarding scopes. with loops,  are as they are.

No new keywords, no overstating the issue.

But does 't=None' have any meaning in Python now?

I guess if it doesn't  anything along the lines of my suggestion
doesn't make much sense.

Art





More information about the Python-list mailing list