Instance method for converting int to str - str() and __str__()

Laura Creighton lac at openend.se
Sat Oct 3 04:31:21 EDT 2015


In a message of Fri, 02 Oct 2015 23:35:28 -0700, neubyr writes:
>I was wondering if there is any resource that explains why certain methods
>like str() and type() were implemented the way they are, rather than
>.to_string() or .type() instance/object methods.
>
>I find instance/object methods more intuitive for this cases, but I am
>wondering why it wasn't implemented it like that.
>
>I know there are equivalents like  __str__() and __class__ , but passing
>object to str() or type() seems more popular.
>
>Any resources for reading or some background information would be helpful.
>
>- CS
>
>-- 
>https://mail.python.org/mailman/listinfo/python-list
>

start reading here:
https://www.python.org/download/releases/2.2/descrintro/
and keep searching and reading about type-class unification in Python.

The answer is, because types and classes used to be very different
things, and you _couldn't_.

Laura



More information about the Python-list mailing list