[Python-ideas] Dunder method to make object str-like
Ethan Furman
ethan at stoneleaf.us
Thu Apr 7 15:12:18 EDT 2016
On 04/07/2016 12:06 PM, Terry Reedy wrote:
> On 4/7/2016 11:03 AM, Ethan Furman wrote:
>> On 04/07/2016 07:07 AM, Random832 wrote:
>>> What's __index__ for?
>>
>> __index__ is a way to get an int from an int-like object without losing
>> information; so it fails with values like 3.4, but should succeed with
>> values like Fraction(4, 2).
>>
>> __int__ is a way to convert the value to an int, so 3.4 becomes 3 (and
>> and the 4/10's is lost).
>
> Why is that a problem?
It isn't. I was explaining the difference between __int__ and __index__.
--
~Ethan~
More information about the Python-ideas
mailing list