Python instance attribute not being recognized -
this question has reply here:
i maintain on getting type error 2 answersi have next code in python:
class state: def _init_(self): self.x=list([]) self.possiblechests=list([]) self.visitedchests=list([]) def checkkeys(self): print self.x def addkey(self,x): self.x.append(key) current_state=state() future_state=state() current_state.addkey(4)
when run next error:
attributeerror: state instance has no attribute 'x'
why 'x' not beingness recognized instance attribute?
you need double underscores around __init__
:
def __init__(self):
otherwise, python treat function normal method , not __init__
special method.
python attributes instance
No comments:
Post a Comment