Skip to content

Instantly share code, notes, and snippets.

@naltimari
Last active July 22, 2020 11:06
Show Gist options
  • Save naltimari/77c30bb686015da988400fc7552db011 to your computer and use it in GitHub Desktop.
Save naltimari/77c30bb686015da988400fc7552db011 to your computer and use it in GitHub Desktop.
Python App Config Wrapper
## nice wrapper for options (config) that you keep in code
## (example is a hard-coded python dict, but could be ini file, envvars or DB table)
options = {
'key1': 'value1',
'key2': 'value2',
'key3': 'value3',
'debug': True
}
class configwrapper(object):
def __call__(self, *args):
from operator import itemgetter
return itemgetter(*args)(self)
def __getitem__(self, key):
return options.get(key.lower())
get = configwrapper()
# from anywhere in your code, you would do this:
import config
k1,k2 = config.get('Key1', 'Key2')
debug = config.get('debug')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment