Lists in ConfigParser

后端 未结 15 2017
清酒与你
清酒与你 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 10:11

    Coming late to this party, but I recently implemented this with a dedicated section in a config file for a list:

    [paths]
    path1           = /some/path/
    path2           = /another/path/
    ...
    

    and using config.items( "paths" ) to get an iterable list of path items, like so:

    path_items = config.items( "paths" )
    for key, path in path_items:
        #do something with path
    

    Hope this helps other folk Googling this question ;)

提交回复
热议问题