On Tue, 13 Mar 2018 12:40:26 +0100, Robin Koch wrote:
> Am 13.03.2018 um 12:16 schrieb Steven D'Aprano:
>
>> How do Fractions convert to ints when they have no __int__ method?
>
> It uses __trunc__:
Ah, thanks!
--
Steve
--
https://mail.python.org/mailman/listinfo/python-list
Am 13.03.2018 um 12:16 schrieb Steven D'Aprano:
How do Fractions convert to ints when they have no __int__ method?
It uses __trunc__:
| In general, the int() conversion should try __int__() first and if
| it is not found, try
__trunc__().[https://www.python.org/dev/peps/pep-3141/]
--
Robin
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 "", line 1, in
AttributeError: 'Fraction' object has no attribute '__int__'
--
Ste