【问题标题】:Python get diff for ConfigParserPython 获取 ConfigParser 的差异
【发布时间】:2018-11-27 03:02:47
【问题描述】:

假设我已经初始化了新旧配置

from ConfigParser import ConfigParser

old_config = ConfigParser()
old_config.read(config_file1)
new_config = ConfigParser()
new_config.read(config_file2)

如何区分这两个配置?

【问题讨论】:

  • 您必须编写一些代码。不太可能有自动工具。

标签: python configuration configuration-files configparser


【解决方案1】:

您可以使用以下方法将每个配置实例转换为字典:

old_dict = old_config._sections
new_dict = new_config._sections

然后使用以下方法获取差异:

set(old_dict.items()) ^ set(new_dict.items())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多