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

Vito De Tullio vito.detullio at gmail.com
Sat Apr 9 01:58:07 EDT 2016

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?

By ZeD

More information about the Python-ideas mailing list