import configparser config=configparser.ConfigParser() config.read('config.ini')#a.cfg a.ini a.cnf都可以 print(config.sections())#读出所有的标题['egon', 'alex'] print(config.options('egon'))#读出某个标题下面的所有配置项key['password', 'age', 'salary', 'is_beautiful'] print(config.get('egon','age'))#读出valuez值18 res=config.get('egon','age') print(res,type(res))#所有读出的值都为str类型 res=config.getint('egon','age')#会转成整型 print(res) res=config.getfloat('egon','salary')#转成浮点型 n=config.getboolean('egon','is_beautiful')#bool值 res=config.items('egon')#取出所有的key:value值# print(res)为[('password', "'123'"), ('age', '18'), ('salary', '3.3'), ('is_beautiful', 'Ture')] print(res)
python的configparser模块
最新推荐文章于 2022-11-03 11:14:00 发布