Skip to content

Instantly share code, notes, and snippets.

@alecordev
Last active July 24, 2018 16:29
Show Gist options
  • Save alecordev/c5a049076402d1126f43027837523d37 to your computer and use it in GitHub Desktop.
Save alecordev/c5a049076402d1126f43027837523d37 to your computer and use it in GitHub Desktop.
Python 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__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment