for x in... x remains global
Antoine De Groote
antoine at vo.lu
Wed Nov 8 06:49:23 EST 2006
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 block.
Is there a reason this is not the case? Maybe there are PEPs or
something else about the matter that you can point me to?
Regards,
antoine
More information about the Python-list
mailing list