Lists in ConfigParser

后端 未结 15 1995
清酒与你
清酒与你 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:13

    This is what I use for lists:

    config file content:

    [sect]
    alist = a
            b
            c
    

    code :

    l = config.get('sect', 'alist').split('\n')
    

    it work for strings

    in case of numbers

    config content:

    nlist = 1
            2
            3
    

    code:

    nl = config.get('sect', 'alist').split('\n')
    l = [int(nl) for x in nl]
    

    thanks.

提交回复
热议问题