[Python-ideas] Dunder method to make object str-like
random832 at fastmail.com
Thu Apr 7 12:16:31 EDT 2016
On Thu, Apr 7, 2016, at 11:01, Paul Moore wrote:
> >> For that matter, what constitutes a "lossless conversion to str"?
> > What's __index__ for?
> I don't follow. It's for indexing, which requires an integer.
Sure, but why isn't int() good enough? For the same reason you only want
the kinds of objects that implement __index__ (and not, say, a float or
a string that happens to be numeric) for indexing, you only want the
kinds of objects that implement this method for certain purposes.
More information about the Python-ideas