'int' object is not callable
- by Oscar Reyes
I'm trying to define a simply Fraction class
And I'm getting this error:
python fraction.py
Traceback (most recent call last):
File "fraction.py", line 20, in <module>
f.numerator(2)
TypeError: 'int' object is not callable
The code follows:
class Fraction(object):
def __init__( self, n=0, d=0 ):
self.numerator = n
self.denominator = d
def get_numerator(self):
return self.numerator
def get_denominator(self):
return self.denominator
def numerator(self, n):
self.numerator = n
def denominator( self, d ):
self.denominator = d
def prints( self ):
print "%d/%d" %(self.numerator, self.denominator)
if __name__ == "__main__":
f = Fraction()
f.numerator(2)
f.denominator(5)
f.prints()
I thought it was because I had numerator(self) and numerator(self, n) but now I know Python doesn't have method overloading ( function overloading ) so I renamed to get_numerator but that's not the problems.
What could it be?