How do Fractions convert to int?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Mar 13 07:16:59 EDT 2018


How do Fractions convert to ints when they have no __int__ method?

py> from fractions import Fraction
py> x = Fraction(99, 2)
py> int(x)  # works fine
49
py> x.__int__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Fraction' object has no attribute '__int__'




-- 
Steve




More information about the Python-list mailing list