-
-
Save alecordev/c5a049076402d1126f43027837523d37 to your computer and use it in GitHub Desktop.
Python SimpleNamespace
This file contains 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 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