文件格式:properties,config,ini,log4j(一般用来java配置日志文件的)
配置文件如下
1 [BUTTON] 2 button = all 3 4 [LEMON] 5 num = 89 6 name = 小明
其中option,value相当于key,value
读取配置文件
1 import configparser 2 3 cf = configparser.ConfigParser() 4 cf.read('case.config', encoding='utf-8') 5 # 读取配置文件的数据1 6 # res_1 = cf.get('BUTTON', 'button') 7 # print(res_1) 8 print(cf.sections()) # 读取所有的区 9 print(cf.items('BUTTON')) # 读取区的键值对 10 11 # 读取配置文件的数据2 12 res_2 = cf['BUTTON']['button'] 13 print(res_2)
print(cf.get('LEMON', 'name')) # 读取的option的值
数据类型的讨论,都是字符串的类型