python configparse
2021-06-17 16:04
标签:parse school 写入 add exists one match .config 0.12 python configparse 标签:parse school 写入 add exists one match .config 0.12 原文地址:https://www.cnblogs.com/lajiao/p/9719947.html# 参考: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)
文章标题:python configparse
文章链接:http://soscw.com/index.php/essay/95110.html