Skip to content

Instantly share code, notes, and snippets.

@AstraLuma
Created November 16, 2011 15:36
Show Gist options
  • Save AstraLuma/1370378 to your computer and use it in GitHub Desktop.
Save AstraLuma/1370378 to your computer and use it in GitHub Desktop.
Config Abstractor
class Config(object):
_sources = []
def __init__(self, sources):
self._sources = []
for s in sources:
if isinstance(s, basestring):
_sources.append(vars(load_file(s))) #TODO: How to load a file?
elif isinstance(s, dict):
_sources.append(s.copy())
else:
_sources.append(vars(s))
def __getattr__(self, key):
for s in self._sources:
try:
return s[key]
except KeyError:
continue
else:
raise AttributeError
@AstraLuma
Copy link
Author

Should probably use __slots__, since vars() won't work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment