Is it appropriate to use a class variable accessed with self
as a loop variable (aka loop counter, target_list, or iterated item)? I have not found a standard which describes this situation. The following python code is valid and produces the expected result ("1, 2, 3") but it feels wrong somehow:
class myClass():
foo = None
def myfunc(self):
for self.foo in [1, 2, 3]:
print(self.foo)
return
myClass().myfunc()
I have not found a definitive answer that suggests using self.foo
would be considered good or bad programming.
More specifically:
- Does the MWE pass muster for standards?
- Is the MWE behaving like I claim or is something else happening here?