[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-dev
Subject:    Re: [Python-Dev] Fwd:  str(IntEnum)
From:       Ethan Furman <ethan () stoneleaf ! us>
Date:       2015-02-20 18:44:45
Message-ID: 54E7809D.7020000 () stoneleaf ! us
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


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

> I think that a decent rule around the usage of __str__ is that it shoul=
d
> 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 fal=
l
> 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 i=
mportant (for humans) than the actual value, so
__str__ is defined as being the Enum class name plus the Enum member name=
=2E  The __repr__ has that as well as the
underlying value (occasionally it's useful to know that, too ;) .

--
~Ethan~


["signature.asc" (application/pgp-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/python-dev-marcsub-zyf4%40marc.info


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic