Parsing configure file with same section name in python

后端 未结 4 1128
囚心锁ツ
囚心锁ツ 2020-12-30 06:44

I try to parse file like:

[account]
User = first

[account]
User = second

I use ConfigParser in Python, but when i read file:



        
4条回答
  •  悲哀的现实
    2020-12-30 06:55

    Unfortunately, the format of the provided ini file is not correct according standards. A section's name must be unique in the document.

    If you can change the file-format (I already read that you cannot, but for completeness...), then a solution like this would be appropriate:

    [accounts]
    keys= account1, account2
    
    [account1]
    User = first
    
    [account2]
    User = second
    

    If you really can't alternate the file's format, then I fear that your only option is to parse manually the configuration file.

提交回复
热议问题