简体   繁体   English

没有分隔符的ConfigParser

[英]ConfigParser with no delimiter

Using Python 3.5 and ConfigParser. 使用Python 3.5和ConfigParser。

I want to use a config file like this: 我想使用这样的配置文件:

[Section]
key1
key2
key3

ie no values. 即没有价值。 By default ConfigParser requires values but I can pass allow_no_values=True to the constructor to handle that. 默认情况下,ConfigParser需要值,但我可以将allow_no_values=True传递给构造函数来处理它。

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 . 如果使用一个空列表,它会抱怨option '' in section 'Section' already exists而如果我得到'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. 我必须指定一些我“希望”永远不会被使用的字符,这种感觉并不是最佳的。

你可以设置delimiters=('\\n',) ,理论上它意味着键/值分隔符是一个换行符,它永远不会发生,因为行分隔符也是一个换行符,它似乎优先。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM