python中ConfigParser是什么

1、将数据库连接参数的配置写入配置文件,然后使用ConfigParser进行管理。

在连接数据库时,我们可以读取配置参数,然后生成连接字符串。

2、ConfigParser本身就提供了生成连接字符串的功能。

实例

$catdb.conf
[DEFAULT]
conn_str=%(dbn)s://(%user)s:%(pw)s@%(host)s:%(port)s/%(db)s
dbn=mysql
user=root
pw=root
host=localhost
port=3306
db=test

以上就是python中ConfigParser的介绍,希望对大家有所帮助更多Python学习指路:Python基础教程

发表回复