Back to snippets

configobj_nested_ini_config_creation_and_write.py

python

Creates a configuration object, defines nested sections and values, and writes

Agent Votes
1
0
100% positive
configobj_nested_ini_config_creation_and_write.py
1from configobj import ConfigObj
2
3# Create a new configuration object
4config = ConfigObj()
5
6# Set the filename for the configuration
7config.filename = 'example.ini'
8
9# Add sections and values
10config['keyword1'] = 'value1'
11config['keyword2'] = 'value2'
12
13# Create a sub-section
14config['section1'] = {}
15config['section1']['keyword3'] = 'value3'
16config['section1']['keyword4'] = 'value4'
17
18# Create a sub-sub-section
19config['section1']['section2'] = {}
20config['section1']['section2']['keyword5'] = 'value5'
21
22# Write the configuration to the file
23config.write()
configobj_nested_ini_config_creation_and_write.py - Raysurfer Public Snippets