Skip to content

Instantly share code, notes, and snippets.

@evan-burke
Last active August 12, 2020 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evan-burke/041f6522d8b9f509f21082596aa5163a to your computer and use it in GitHub Desktop.
Save evan-burke/041f6522d8b9f509f21082596aa5163a to your computer and use it in GitHub Desktop.
python configfile parser example
# because I have to look up the syntax every time:
import configparser
CONFIG_FILENAME = "/path/to/config.file"
# or
# CONFIG_FILENAME = "../relative/path/to/config.file"
# for current dir, just: "config.file"
config = configparser.ConfigParser()
_ = config.read(CONFIG_FILENAME)
# then config entries are in:
config[section][key]
# e.g.,
config['db']['host']
# full spec:
# https://docs.python.org/3/library/configparser.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment