Created
November 16, 2011 15:36
-
-
Save AstraLuma/1370378 to your computer and use it in GitHub Desktop.
Config Abstractor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should probably use
__slots__
, sincevars()
won't work as expected.