Created
November 12, 2009 23:03
-
-
Save silas/233403 to your computer and use it in GitHub Desktop.
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
my_list = [1, 2, 3] | |
server = 'localhost' |
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 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