1、config.ini 文件 

[log]
name=py30
level=INFO

[mysql]
username=python
passwd=123456

2、读取ini配置文件数据(conf.py)

"""
#格式
[section] -- 区域
option=value --属性
"""

from configparser import ConfigParser
#实例化对象
conf = ConfigParser()
#读取某一个配置文件
conf.read('config.ini',encoding='utf-8')
#获取配置文件中的section区域下的optionde 值
value = conf.get('log','name')
print(value)
#获取配置文件中section或option下所有值
# s=conf.sections('log')
# s =conf.options('log')
# print(s)

运行结果: py30




--end--
posted on 2022-12-08 17:03  给天使看的戲  阅读(70)  评论(0编辑  收藏  举报