Created
November 19, 2018 11:50
-
-
Save Mec-iS/3a1be1014e811f0587d4688fa2423670 to your computer and use it in GitHub Desktop.
Python: A generic structure to be used to access dictionaries
This file contains hidden or 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
"""As in https://stackoverflow.com/a/1305663""" | |
class Struct: | |
def __init__(self, **entries): | |
self.__dict__.update(entries) | |
def __repr__(self): | |
return '<%s>' % str('\n '.join('%s : %s' % (k, repr(v)) for (k, v) in self.__dict__.iteritems())) | |
def __str__(self): | |
return str(self.__dict__) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment