I have a class Player, and i am trying to edit one of its attributes. However, I keep on coming up with an error in a for loop within my method:
class Player:
#bunch of attributes
X = 1
Y = 1
def foo(self, bar):
for i in [X,Y]:
self.i += bar.i
However, this error shows up:
AttributeError: Player instance has no attribute 'i'
What is causing this error?
getattr. Also, your code will actually raiseNameErrorsince there's no variable calleditem.