[Python-ideas] Dunder method to make object str-like
rosuav at gmail.com
Sat Apr 9 02:00:14 EDT 2016
On Sat, Apr 9, 2016 at 3:58 PM, Vito De Tullio <vito.detullio at gmail.com> wrote:
> Chris Angelico wrote:
>> 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.
>> Obviously str will have this dunder method, returning self. Most other
>> core types (notably 'object') will not define it. Absence of this
>> method implies that the object cannot be treated as a string.
> do you expect int to define it?
Nope! An integer cannot be treated as a string.
More information about the Python-ideas