'int' object is not callable error python -
hey guys getting "typeerror: 'int' object not callable" error when run code, did research , think it's variable naming? please explain me wrong?
class account(object): def set(self, bal): self.balance = bal def balance(self): return balance
here example run:
>>> = account() >>> a.set(50) >>> a.balance() traceback (most recent call last): file "<pyshell#12>", line 1, in <module> a.balance() typeerror: 'int' object not callable
you masking method balance
instance attribute balance
. rename 1 or other. rename instance attribute pre-pending underscore example:
def set(self, bal): self._balance = bal def balance(self): return self._balance
attributes on instance trump on class (except data descriptors; think property
s). class definitions documentation:
variables defined in class definition class attributes; shared instances. instance attributes can set in method
self.name = value
. both class , instance attributes accessible through notation “self.name
”, , instance attribute hides class attribute same name when accessed in way.
Comments
Post a Comment