Skip to content

Instantly share code, notes, and snippets.

@klenwell
Created May 26, 2013 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klenwell/5654486 to your computer and use it in GitHub Desktop.
Save klenwell/5654486 to your computer and use it in GitHub Desktop.
Converts Python dict to object so that d['some_key'] can be accessed at d.some_key
# -*- coding: utf-8 -*-
"""
DictObject
Converts dict to object
"""
from collections import defaultdict
class DictObject(defaultdict):
def __getattr__(self, key):
return self[key]
def __setattr__(self, key, val):
self[key]=val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment