Created
December 20, 2013 11:57
-
-
Save dansondergaard/8053781 to your computer and use it in GitHub Desktop.
Symbols in Python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class symbol(object): | |
| _symbols = {} | |
| def __new__(cls, name): | |
| if name not in symbol._symbols: | |
| symbol._symbols[name] = object.__new__(cls, name) | |
| return symbol._symbols[name] | |
| def __init__(self, name): | |
| self.name = name | |
| assert symbol('foo') == symbol('foo'), 'symbols with same name must be equal' | |
| assert symbol('foo') != symbol('bar'), 'symbols with different names must not be equal' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment