Skip to content

Instantly share code, notes, and snippets.

@roodee
Last active September 12, 2023 11:58
Show Gist options
  • Save roodee/ac9718309b8003869a29445350cd9655 to your computer and use it in GitHub Desktop.
Save roodee/ac9718309b8003869a29445350cd9655 to your computer and use it in GitHub Desktop.
Parse configuration file
# 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