Last active
August 27, 2015 03:00
-
-
Save jxinging/67a5971e980919c54ef2 to your computer and use it in GitHub Desktop.
Python config loader
This file contains hidden or 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
import imp | |
class ConfigLoader(object): | |
def __init__(self): | |
self.__conf = None | |
def load_file(self, path): | |
assert self.__conf is None | |
if self.__conf is None: | |
self.__conf = imp.load_source('config', path) | |
return self.__conf | |
def load_object(self, obj): | |
assert self.__conf is None | |
if self.__conf is None: | |
self.__conf = obj | |
return self.__conf | |
def __getattr__(self, item): | |
return getattr(self.__conf, item) | |
conf = ConfigLoader() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment