configparser — Easy Playground
Read and write INI-style configuration files
Python Playground
import configparser
from io import StringIO
config = configparser.ConfigParser()
config.read_string("""
[database]
host = localhost
port = 5432
name = mydb
[app]
debug = true
""")
print(config["database"]["host"])
print(config.getint("database", "port"))
print(config.getboolean("app", "debug"))
Output
Click "Run" to execute your code
The configparser module is part of Python's standard library. Read and write INI-style configuration files.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?