Read all the contents in ini file into dictionary with Python

前端 未结 8 1882
天涯浪人
天涯浪人 2020-12-04 22:28

Normally, I code as follows for getting a particular item in a variable as follows

try:
    config = ConfigParser.ConfigParser()
    config.read(self.iniPath         


        
8条回答
  •  粉色の甜心
    2020-12-04 23:10

    I know that this question was asked 5 years ago, but today I've made this dict comprehension thingy:

    parser = ConfigParser()
    parser.read(filename)
    confdict = {section: dict(parser.items(section)) for section in parser.sections()}
    

提交回复
热议问题