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
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
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
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
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):