configparser 读取与赋值

import configparser,os,unittest

'''读操作'''

config = configparser.ConfigParser()

# b=config.read(r'C:UsershuiPycharmProjectsoride ew_case est_write.ini')
b=config.read('./test.ini')#获取当前目录下的配置文件
print(b)
a=config.get('ck','token') #获取配置文件 指定的值
print(a)


'''写操作'''
b=config.read(r'./test.ini')
config.add_section('headers')
c=config.set('headers','ip','127.0.0.1')
c=config.set('headers','host','localhost')
c=config.set('headers','port','8080')
# c=config.write(open("./test.ini", "a"))#追加填写
c=config.write(open('./test.ini','w'))#覆盖,如有,则报错
print(c)
原文地址:https://www.cnblogs.com/yanhuidj/p/11792349.html