[Python-Dev] Fwd: str(IntEnum) (original) (raw)
Ethan Furman ethan at stoneleaf.us
Fri Feb 20 19:44:45 CET 2015
- Previous message: [Python-Dev] str(IntEnum)
- Next message: [Python-Dev] Update to PEP 11 to clarify garnering platform support
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
-------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: <http://mail.python.org/pipermail/python-dev/attachments/20150220/eeff7a66/attachment.sig>
- Previous message: [Python-Dev] str(IntEnum)
- Next message: [Python-Dev] Update to PEP 11 to clarify garnering platform support
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]