Skip to content

Instantly share code, notes, and snippets.

@silas
Created November 12, 2009 23:03
Show Gist options
  • Save silas/233403 to your computer and use it in GitHub Desktop.
Save silas/233403 to your computer and use it in GitHub Desktop.
my_list = [1, 2, 3]
server = 'localhost'
class ConfigOptions(object):
def __init__(self, path):
self.config = {}
self.path = path
execfile(self.path, self.config, self.config)
def __contains__(self, name):
return name in self.config or name in self
def __getattr__(self, name):
try:
return self.config[name]
except KeyError:
try:
return self[name]
except KeyError:
raise AttributeError(name)
options = ConfigOptions('test.conf')
print options.my_list
print options.server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment