Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConfigParser with no delimiter

Using Python 3.5 and ConfigParser.

I want to use a config file like this:

[Section]
key1
key2
key3

i.e. no values. By default ConfigParser requires values but I can pass allow_no_values=True to the constructor to handle that.

However the parser will still try to split on the delimiters which by default are ('=', ':'). Thus my lines can't include any of them by default. But I don't want to delimit on anything - none of my lines will ever have a value.

Passing delimiters=() or [] or None does not work. If using an empty list it complains that option '' in section 'Section' already exists while if None I get 'NoneType' is not iterable.

So is there no way to make sure that splitting never happens ? It does not feel optimal that I have to specify some char that I "hope" will never be used.

like image 467
Zitrax Avatar asked Oct 30 '22 04:10

Zitrax


1 Answers

You can set delimiters=('\n',) which in theory means the key/value delimiter is a newline, which will never happen because the line delimiter is also a newline and it seems to take precedence.

like image 183
John Zwinck Avatar answered Nov 10 '22 00:11

John Zwinck