Skip to content

Instantly share code, notes, and snippets.

@upsuper
Last active December 31, 2015 14:49
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 upsuper/8003262 to your computer and use it in GitHub Desktop.
Save upsuper/8003262 to your computer and use it in GitHub Desktop.
Constants
#!/usr/bin/env python
# - * - coding: UTF-8 - * -
class Constants(object):
__slots__ = ['_d']
def __init__(self, d):
self._d = d
for k, v in self._d.items():
if isinstance(v, dict):
self._d[k] = type(self)(v)
def __getattr__(self, name):
if name not in self._d:
raise AttributeError(repr(name))
return self._d[name]
c = Constants({
'a': {
'aa': 1,
'bb': 2
},
'b': 3
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment