-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
Today's configparser module does not consider lines being properly indented and starting with a comment_prefixes to be part of a multiline value. This can lead to unintended data loss during reading an INI file as:
config.ini
# I am a comment
# I am also a comment
[dummy]
# I am a comment
key = I am a multiline
# I am a comment
# multiline part which is not considered but should be
being again part
# I am a comment
test.py
import configparser
config = configparser.ConfigParser(comment_prefixes='#', interpolation=None, inline_comment_prefixes=None)
config.read('config.ini')
print(config['dummy']['key'])
# output: 'I am a multiline\nbeing again part'
# expected output: 'I am a multiline\n# multiline part which is not considered but should be\nbeing again part''
Therefore, I would propose to add a new parameter allow_comment_in_value (default False) in the ConfigParser class to support such scenarios. Please note that in this scenario the comment_prefixes is set to '#' and any interpolation is disabled!
Thanks and best regards!
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement