Python ConfigParser 模块重命名部分

bph*_*bph 1 python configparser

如何重命名ConfigParser对象中的部分?

bph*_*bph 6

示例辅助函数 - 真的很傻,但它可能会为某人节省几分钟的工作......

def rename_section(cp, section_from, section_to):

    items = cp.items(section_from)

    cp.add_section(section_to)

    for item in items:
        cp.set(section_to, item[0], item[1])

    cp.remove_section(section_from)
Run Code Online (Sandbox Code Playgroud)