'int' object is not callable
Posted
by Oscar Reyes
on Stack Overflow
See other posts from Stack Overflow
or by Oscar Reyes
Published on 2010-04-23T22:29:35Z
Indexed on
2010/04/23
22:33 UTC
Read the original article
Hit count: 280
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?
© Stack Overflow or respective owner