for x in... x remains global

2006-11-08 Thread Antoine De Groote
for x in range(3): pass After this statement is executed x is global variable. This seems very unnatural to me and caused me 3 three days of debugging because I was unintentionally using x further down in my program (typo). I would have thought that variables like this are local to the for

Re: for x in... x remains global

2006-11-08 Thread Diez B. Roggisch
Antoine De Groote wrote: for x in range(3): pass After this statement is executed x is global variable. This seems very unnatural to me and caused me 3 three days of debugging because I was unintentionally using x further down in my program (typo). I would have thought that variables like

Re: for x in... x remains global

2006-11-08 Thread Ben Finney
Antoine De Groote [EMAIL PROTECTED] writes: for x in range(3): pass After this statement is executed x is global variable. Not exactly. The name 'x' is bound at the scope of the 'for' statement, and remains bound after the 'for' statement stops, just as it would be if it was bound in any

Re: for x in... x remains global

2006-11-08 Thread Duncan Booth
Antoine De Groote [EMAIL PROTECTED] wrote: for x in range(3): pass After this statement is executed x is global variable. This seems very unnatural to me and caused me 3 three days of debugging because I was unintentionally using x further down in my program (typo). I would have thought

Re: for x in... x remains global

2006-11-08 Thread skip
Diez It's an somewhat unfortunate fact that loop variables leak to the Diez outer scope. List-comps as well, btw. It's unfortunate that loop variables leak from list comprehensions (they don't leak in genexps). It's by design in for loops though. Consider: for i in range(10):