[Python-Dev] elimination of scope bleeding of iteration variables (original) (raw)
Greg Ewing greg.ewing at canterbury.ac.nz
Mon May 1 11:34:17 CEST 2006
- Previous message: [Python-Dev] PEP 3102: Keyword-only arguments
- Next message: [Python-Dev] More on contextlib - adding back a contextmanager decorator
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Nick Coghlan wrote:
However, the scoping of for loop variables won't change, as the current behaviour is essential for search loops that use a break statement to terminate the loop when the item is found.
It occurs to me that there's a middle ground here: leave the loop variable scope alone, but make it an error to use the same variable in two different loops at the same time.
e.g.
for x in stuff: if its_what_were_looking_for(x): break snarfle(x) for x in otherstuff: dosomethingelse(x)
would be fine, but
for x in stuff: for x in otherstuff: dosomethingelse(x)
would be a SyntaxError because the inner loop is trying to use x while it's still in use by the outer loop.
-- Greg
- Previous message: [Python-Dev] PEP 3102: Keyword-only arguments
- Next message: [Python-Dev] More on contextlib - adding back a contextmanager decorator
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]