[Python-ideas] Dunder method to make object str-like
python at mrabarnett.plus.com
Thu Apr 7 10:58:12 EDT 2016
On 2016-04-07 15:10, M.-A. Lemburg wrote:
> On 07.04.2016 15:04, Chris Angelico wrote:
>> This is a spin-off from the __fspath__ discussion on python-dev, in
>> which a few people said that a more general approach would be better.
>> Proposal: Objects should be allowed to declare that they are
>> "string-like" by creating a dunder method (analogously to __index__
>> for integers) which implies a loss-less conversion to str.
> I must be missing something... we already have a method for this:
It's for making string-like objects into strings.
__str__ isn't suitable because, ints, for example, have a __str__
method, but they aren't string-like.
More information about the Python-ideas