Skip to content

Instantly share code, notes, and snippets.

@nzjrs nzjrs/
Created Sep 7, 2011

What would you like to do?
Namespaced dict wrapper
import UserDict
class DotDict(UserDict.IterableUserDict):
def __init__(self):
def __setitem__(self, key, val):
bits = key.split(".")
if bits[0] not in[bits[0]] = {}
if len(bits) == 2:[bits[0]][bits[1]] = val
elif len(bits) == 3:
if bits[1] not in[bits[0]]:[bits[0]][bits[1]] = {}[bits[0]][bits[1]][bits[2]] = val
if __name__ == "__main__":
d = DotDict()
d["lilypad.upload.protocol"] = "stk500"
d[""]="LilyPad Arduino"
print d["lilypad"]["upload"]["maximum_size"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.