Created
February 10, 2014 20:56
-
-
Save timotheus/8924002 to your computer and use it in GitHub Desktop.
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 ResponseDataObject(object): | |
def __init__(self, mydict={}): | |
self._load_dict(mydict) | |
def __repr__(self): | |
return str(self) | |
def __str__(self): | |
return unicode(self).encode('utf-8') | |
def __unicode__(self): | |
return str(self.__dict__) | |
def _load_dict(self, mydict): | |
for a in mydict.items(): | |
if isinstance(a[1], dict): | |
o = ResponseDataObject(a[1]) | |
setattr(self, a[0], o) | |
elif isinstance(a[1], list): | |
objs = [] | |
for i in a[1]: | |
objs.append(ResponseDataObject(i)) | |
setattr(self, a[0], objs) | |
else: | |
setattr(self, a[0], a[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment