Skip to content

Instantly share code, notes, and snippets.

@jxinging
Last active August 27, 2015 03:00
Show Gist options
  • Save jxinging/67a5971e980919c54ef2 to your computer and use it in GitHub Desktop.
Save jxinging/67a5971e980919c54ef2 to your computer and use it in GitHub Desktop.
Python config loader
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