[issue22253] ConfigParser does not handle files without sections

kernc report at bugs.python.org
Fri Sep 12 18:46:15 CEST 2014


kernc added the comment:

>
> I am dubious that there are any with a mixture of both sections and
> additional option lines at the top without a section.
>

rsyncd.conf [1] is one such example, and I wouldn't say there aren't
countless more in the wild.

> Anyone writing an app and planning to parse a .ini file can add [Start] or
> [Setup] at the top.
>

Indeed. Here lies the problem of this unfortunate issue:
MissingSectionHeaderError is only ever caught [9] to mitigate this **awful
default behavior** and attach a dummy section at the top, as you say. Or
can anyone care to propose another relevant use case for this poorly (un-)
thought through exception?

> I think a more useful new configparser feature would be to keep comment
> lines and write them back out after a configuration is changed.
>

While this is very much off-topic, configobj [3] does too seem to have done
so since ages.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22253>
_______________________________________


More information about the Python-bugs-list mailing list