python操作.ini配置文件

2024-12-03 15:08:02

在平常工作中,我们一般会将一些公共的配置信息,放在.ini文件中,但是python是怎么读取.ini的信息呢?

工具/原料

Python3.6

Windows10

Python 3.6

.ini文件内容的编写

1、我们以数据库的连接配置信息编写为例

python操作.ini配置文件

安装包

1、在dos窗口命令行中,直接输入pip installconfigparser

python操作.ini配置文件

2、通过section获取option值

python操作.ini配置文件

4、通过section获取所有option的值

python操作.ini配置文件
猜你喜欢