Parse variable from config file

You can store variables in an ini file for later executions of the script instead of hardcoding the values in the script. Here is the content of config.ini :

[section1]
var_a:hello
var_b:world
[section2]
myvariable: 42

Use the configparser library for an easy access and parsing of the file.

import configparser


config = configparser.ConfigParser()
config.read("config.ini")
var_a = config.get("section1", "var_a")
var_b = config.get("section1", "var_b")

myvariable = config.get("section2", "myvariable")


print(var_a, var_b)

print(myvariable)
hello world
42