Skip to content

Instantly share code, notes, and snippets.

@dmiro
Last active May 4, 2016 09:26
Show Gist options
  • Save dmiro/05e8c748dce1cac5eb6eada745cd5171 to your computer and use it in GitHub Desktop.
Save dmiro/05e8c748dce1cac5eb6eada745cd5171 to your computer and use it in GitHub Desktop.
anonymous class
#https://docs.python.org/3/library/types.html#types.SimpleNamespace
class SimpleNamespace:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
keys = sorted(self.__dict__)
items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys)
return "{}({})".format(type(self).__name__, ", ".join(items))
def __eq__(self, other):
return self.__dict__ == other.__dict__
#
# options = SimpleNamespace(answer=42, linelen = 80, font='courier')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment