简体   繁体   中英

Python get diff for ConfigParser

Let say I have old and new configurations initialized

from ConfigParser import ConfigParser

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

How can I get the difference between these two configs?

You can turn each of the config instances into a dictionary using:

old_dict = old_config._sections
new_dict = new_config._sections

then get the difference using:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM