Last active
May 4, 2016 09:26
-
-
Save dmiro/05e8c748dce1cac5eb6eada745cd5171 to your computer and use it in GitHub Desktop.
anonymous class
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
#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