Skip to content

Instantly share code, notes, and snippets.

@Mec-iS
Created November 19, 2018 11:50
Show Gist options
  • Save Mec-iS/3a1be1014e811f0587d4688fa2423670 to your computer and use it in GitHub Desktop.
Save Mec-iS/3a1be1014e811f0587d4688fa2423670 to your computer and use it in GitHub Desktop.
Python: A generic structure to be used to access dictionaries
"""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