[配置]的Python读取INI

apache_conf
阅读 40 收藏 0 点赞 0 评论 0

config.ini
[db] 
server = 
username = 
password = 
database = 
driver = {ODBC Driver 17 for SQL Server}
configparser_test.py
from configparser import ConfigParser
def load_config(self):
    cf = ConfigParser()
    cf.read('config.ini')
    server = cf.get('db', 'server')
    username = cf.get('db', 'username')
    password = cf.get('db', 'password')
    database = cf.get('db', 'database')
    driver = cf.get('db', 'driver')
    return server, username, password, database, driver
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号