79647960

Date: 2025-06-01 21:36:19
Score: 1
Natty:
Report link

To build on Pedro's discovery of support for unnamed sections in Python 3.13, an example:

import configparser

config = "config.ini"

cparser = configparser.ConfigParser(allow_unnamed_section=True)
cparser.read(config)

value = cparser.get(configparser.UNNAMED_SECTION, 'key1')

and while OP has no need to write/modify the original file, for those who do:

cparser.set(configparser.UNNAMED_SECTION, 'key1', 'new_val')

with open(config, 'w') as cf:
    cparser.write(cf)
Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: udance4ever