首页 > 文章列表 > python中ConfigParser是什么

python中ConfigParser是什么

Python ConfigParser
208 2022-08-07

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

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

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

实例

    $cat db.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

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。