Last active
September 12, 2023 11:58
-
-
Save roodee/ac9718309b8003869a29445350cd9655 to your computer and use it in GitHub Desktop.
Parse configuration file
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
# Given is a configuration file in ini-format | |
# It contains sections, parameter names and values like this | |
# | |
# [section] | |
# param1 = value1 | |
# param2 = value2 | |
# | |
# Use configparser to parse the file | |
# Pass the names for section and parameter to retrieve the configured value | |
import configparser | |
config_parser = configparser.ConfigParser() | |
config_parser.read("your_config_file.conf") | |
# value1 | |
val = config_parser[section].get(param1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment