Convert ConfigParser.items('') to dictionary

后端 未结 9 1090
再見小時候
再見小時候 2020-12-12 18:44

How can I convert the result of a ConfigParser.items(\'section\') to a dictionary to format a string like here:

import ConfigParser

config = ConfigParser.Co         


        
9条回答
  •  遥遥无期
    2020-12-12 19:16

    How I did it in just one line.

    my_config_parser_dict = {s:dict(config.items(s)) for s in config.sections()}
    

    No more than other answers but when it is not the real businesses of your method and you need it just in one place use less lines and take the power of dict comprehension could be useful.

提交回复
热议问题