Skip to content

Instantly share code, notes, and snippets.

Created February 20, 2013 07:46
What would you like to do?
softDict make dictionary into another object to access key-value using .propertyname convention
copyright 2013. All right reserved to sooop.
class SoftDict:
Make data in dict to access object's property convention.
def __init__(self, user_dict):
self._user_dict = user_dict
def _parse(self):
for key in self._user_dict.iterkeys():
value = self._user_dict[key]
if type(value) == dict:
value = SoftDict(value)
setattr(self, key, value)
def main():
a = { "meta":{"name":"a", "msg":"OK"},"res":"google"}
b = SoftDict(a)
print b.meta.msg
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment