'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 propertys). 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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -