1、將數(shù)據(jù)庫連接參數(shù)的配置寫入配置文件,然后使用ConfigParser進行管理。

在連接數(shù)據(jù)庫時,我們可以讀取配置參數(shù),然后生成連接字符串。
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
以上就是python中ConfigParser的介紹,希望對大家有所幫助。更多Python學習指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
新聞標題:創(chuàng)新互聯(lián)Python教程:python中ConfigParser是什么
網(wǎng)站網(wǎng)址:
http://www.5511xx.com/article/djphijd.html