ConfigParser: use newline in INI file
Thorsten Kampe
thorsten at thorstenkampe.de
Sat Oct 1 17:58:17 EDT 2016
* Terry Reedy (Sat, 1 Oct 2016 15:44:39 -0400)
>
> On 10/1/2016 10:56 AM, Thorsten Kampe wrote:
>
> > ConfigParser escapes `\n` in ini values as `\\n`. Is there a way to
> > signal to ConfigParser that there is a line break?
>
> Without an example or two, I don't really understand the question enough
> to answer.
>>> !cat INI.ini
[Asciidoc]
_test_stdout = <div class="paragraph">\n<p>Hello, World!</p>\n</div>
>>> import configparser
>>> config = configparser.ConfigParser()
>>> config.read('INI.ini')
['INI.ini']
>>> config['Asciidoc']['_test_stdout']
'<div class="paragraph">\\n<p>Hello, World!</p>\\n</div>'
...as you can see, ConfigParser escaped the backslash by doubling it.
Which is fine in most cases - except when I want to have something
indicating an newline.
Thorsten
More information about the Python-list
mailing list