Intern
What Python modules would you use to write a configuration parser?
sobes.tech AI
Answer from AI
Modules commonly used for writing configuration parsers in Python include:
configparser— for reading and writing INI files.json— for working with JSON format configurations.yaml(via the PyYAML library) — for parsing YAML files.argparse— for handling command-line arguments if the configuration is passed through parameters.
Example of a simple INI configuration parser:
import configparser
config = configparser.ConfigParser()
config.read('settings.ini')
print(config['DEFAULT']['Server'])
The choice of module depends on the format of the configuration file.