[Python-ideas] Dunder method to make object str-like

Chris Angelico rosuav at gmail.com
Thu Apr 7 12:46:32 EDT 2016


On Fri, Apr 8, 2016 at 2:27 AM, M.-A. Lemburg <mal at egenix.com> wrote:
> Not necessarily. In fact, a string.String ABC could have only
> a single method: .__str__() defined.

That wouldn't be very useful; object.__str__ exists and is functional,
so EVERY object would count as a string.

The point of "string-like" is that it can be treated as a string, not
just that it can be converted to one. This is exactly parallel to the
difference between __index__ and __int__; floats can be converted to
int (and will truncate), but cannot be *treated* as ints.

ChrisA


More information about the Python-ideas mailing list