On 02/20/2015 10:24 AM, Demian Brecht wrote:

> I think that a decent rule around the usage of __str__ is that it should
> be a string representation of the value, not of the object. Failing the
> ability to logically coerce the value to a string, it should simply fall
> back to repr(obj).

There are two "stringy" methods for objects:  __repr__ and __str__; if __str__ 
has not been defined __repr__ is
automatically used.

One of the motivating forces behind Enum is that often the name is more 
important (for humans) than the actual value, so
__str__ is defined as being the Enum class name plus the Enum member name.  The 
__repr__ has that as well as the
underlying value (occasionally it's useful to know that, too ;) .

--
~Ethan~

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to