python configparse

# 参考:https://www.cnblogs.com/lily1989/p/8401005.html
#  https://blog.csdn.net/willhuo/article/details/49512557
import configparser
config = configparser.ConfigParser()
config.read('cost.ini')
# 读取
print(config.get('tests', 'ip'))
# 或者print(config['tests']['ip'])
# 写入
try:
    config.add_section("School")
    config.set("School","IP","10.15.40.123")
except configparser.DuplicateSectionError:
    print("Section 'Match' already exists")


with open('cost.ini','w') as fp:
    config.write(fp)

原文地址:https://www.cnblogs.com/lajiao/p/9719947.html