I\'m trying to define a simply Fraction
class
And I\'m getting this error:
python fraction.py
Traceback (most recent call last):
File
You can't overload the name numerator
to refer to both the member variable and the method. When you set self.numerator = n
, you're overwriting the reference to the method, and so when you call f.numerator(2)
, it's trying to do a method call on the member variable, which is an int
, and Python doesn't let you do that. It's like saying x = 2; x(4)
-- it just doesn't make any sense.
You should rename the setter methods to set_numerator
and set_denominator
to remove this naming conflict.