configparser模块
import configparser
config=configparser.ConfigParser()
config.read('config.ini') #a.cfg a.ini a.cnf
# print(config.sections())
# print(config.options('egon'))
# print(config.items('egon'))
# res=config.get('egon','age')
# res=config.getint('egon','age')
# print(res,type(res))
# res=config.getfloat('egon','salary')
# print(res,type(res))
# res=config.getboolean('egon','is_beautiful')
# print(res,type(res))
configparser 配置文件解析模块
何为配置文件? 运行程序时一些参数需要用户来决定,这些参数称之为配置信息,配置信息通常就放在一个文件中
为什么要配置文件? 一些参数我们不能再代码中写死,这样扩展性太低,修改需求时必须修改源 代码,太麻烦
配置文件主要内容 section option 常用方法 read sections options set get 总结:配置文件是非常用的程序扩展方法,其实使用起来⾮常简单