Closed as not planned
Description
The docs state:
[You can use comments]
[Sections Can Be Indented]
can_values_be_as_well = Truebut while sections can indeed be indented, indenting values results in an Exception.
Simple code:
#! /usr/bin/env python3
# -*- coding: UTF-8 -*-
import configparser
config = configparser.ConfigParser()
with open("testconfigparser.cfg") as f:
config.read_file(f)
print(config.get("alpha", "alpha1"))
print(config.get("alpha", "alpha2"))
print(config.get("alpha", "alpha3"))
print(config.get("alpha", "alpha4"))Simple config file:
## configparsertest.cfg
[alpha]
alpha1 = 100
alpha2 = 200
alpha3 = 300
alpha4 = 400Result of having alpha3 (inadvertently) indented by a single space is:
$ python testconfigparser.py
100
200
alpha3 = 300
Traceback (most recent call last):
File "/usr/lib/python3.9/configparser.py", line 789, in get
value = d[option]
File "/usr/lib/python3.9/collections/__init__.py", line 941, in __getitem__
return self.__missing__(key) # support subclasses that define __missing__
File "/usr/lib/python3.9/collections/__init__.py", line 933, in __missing__
raise KeyError(key)
KeyError: 'alpha3'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ullix/geigerlog/geigerlog/misc/Bugs/testconfigparser.py", line 12, in <module>
print(config.get("alpha", "alpha3"))
File "/usr/lib/python3.9/configparser.py", line 792, in get
raise NoOptionError(option, section)
configparser.NoOptionError: No option 'alpha3' in section: 'alpha'
