Greetings everyone. I hope you all had a great Christmas holiday. 8-) I am posting this Enum (named number) class to this list for possible feedback. It can be used as a regular integer but when printed (stringified) it yeilds its name. The hash also makes named numbers with the same integer value into unique dictionary keys. That is the part I am not sure about... Comments appreciated. class Enum(int): __slots__ = ("_name") def __new__(cls, val, name): v = int.__new__(cls, val) v._name = str(name) return v def __str__(self): return self._name def __repr__(self): return "%s(%d, %r)" % (self.__class__.__name__, self,self._name) def __hash__(self): return int.__hash__(self) + hash(self._name) -- -- ------------------------------------------------------------------------- Keith Dart <mailto:kdart at kdart.com> <http://www.kdart.com/> ---------------------------------------------------------------------------- Public key ID: B08B9D2C Public key: <http://www.kdart.com/~kdart/public.key> ============================================================================ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://mail.python.org/pipermail/python-dev/attachments/20031230/df76d679/attachment.bin
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4