python configparse

2021-06-17 16:04

阅读:319

标签:parse   school   写入   add   exists   one   match   .config   0.12   

# 参考: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

标签:parse   school   写入   add   exists   one   match   .config   0.12   

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


评论


亲,登录后才可以留言!