Lists in ConfigParser

后端 未结 15 1992
清酒与你
清酒与你 2020-11-27 09:38

The typical ConfigParser generated file looks like:

[Section]
bar=foo
[Section 2]
bar2= baz

Now, is there a way to index lists like, for in

15条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 09:53

    I landed here seeking to consume this...

    [global]
    spys = richard.sorge@cccp.gov, mata.hari@deutschland.gov
    

    The answer is to split it on the comma and strip the spaces:

    SPYS = [e.strip() for e in parser.get('global', 'spys').split(',')]
    

    To get a list result:

    ['richard.sorge@cccp.gov', 'mata.hari@deutschland.gov']
    

    It may not answer the OP's question exactly but might be the simple answer some people are looking for.

提交回复
热议问题