2 ms·
Looks exactly like namedtuple, why do we need this?
by mixmastamyk 14y ago
Looks exactly like namedtuple, why do we need this?
- reinhardt 14y agoThe only similarity is the signature; semantics are completely unrelated.
- mixmastamyk 14y agoI guess I'm looking for a usecase that namedtuple (or set...) doesn't support. Here's one example: http://pythonpath.wordpress.com/2012/01/26/python-enum-with-namedtuple/ http://pythonpath.wordpress.com/2012/01/26/python-enum-with-...
- shoo 14y agoin that example the values of the enumerated constants are simply integer values, they do not have their own type. so there is nothing stopping you comparing values from two unrelated enumerations, and getting a nonsensical True or False result, instead of a TypeError.
- mixmastamyk 14y agoI suppose that's true and theoretically useful. I don't find myself coding nonsense very often, but python has not been a language that gives much support (or is appropriate) to use cases that can't tolerate any. I now see some good uses for Enum, but (with a skeptical eye to additions) I believe that the reasons to keep the language/libs small are equally important.