ConfigParser: use newline in INI file
Thorsten Kampe
thorsten at thorstenkampe.de
Sun Oct 2 06:34:09 EDT 2016
* Ned Batchelder (Sat, 1 Oct 2016 17:41:28 -0700 (PDT))
>
> On Saturday, October 1, 2016 at 6:25:16 PM UTC-4, Thorsten Kampe wrote:
> > * Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100)
> > >
> > > Thorsten Kampe <thorsten at thorstenkampe.de> writes:
> > >
> > > > ConfigParser escapes `\n` in ini values as `\\n`.
> >
> > Indenting solves the problem. I'd rather keep it one line per value
> > but it solves the problem.
>
> If you want to have \n mean a newline in your config file, you can
> do the conversion after you read the value:
>
> >>> "a\\nb".decode("string-escape")
> 'a\nb'
Interesting approach (although it does not work with Python 3: decode
is only for byte-strings and the string-escape encoding is not
defined).
If I understand this correctly, this is equivalent to
`.replace('\\n', '\n')` ?
Thorsten
More information about the Python-list
mailing list