All pastes #2090547 Raw Edit

Mine

public text v1 · immutable
#2090547 ·published 2011-10-16 18:59 UTC
rendered paste body
import json

def loadConfig(path):
    with open(path) as f:
        obj = json.load(f)
    def get(key):
        parts = key.split(".")
        
        # start up in the root
        subobj = obj
        for part in parts:
            if not part in subobj:
                raise KeyError
            subobj = part
            
        return subobj

    return get


get = loadConfig("config.json")