Last active
August 12, 2020 17:06
-
-
Save evan-burke/041f6522d8b9f509f21082596aa5163a to your computer and use it in GitHub Desktop.
python configfile parser example
This file contains hidden or 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
# 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