Skip to content

Instantly share code, notes, and snippets.

@dansondergaard
Created December 20, 2013 11:57
Show Gist options
  • Select an option

  • Save dansondergaard/8053781 to your computer and use it in GitHub Desktop.

Select an option

Save dansondergaard/8053781 to your computer and use it in GitHub Desktop.
Symbols in Python.
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