python 读取ini 配置文件

安装

pip install configparser

1 配置文件 config.ini:

[MysqlDB]
user=root
passwd=123456
sport=3306
db_name=my_db
charset=utf-8

获取参数:

import configparser

config = configparser.ConfigParser()     

config.read('config.ini')

host=config['MysqlDB']['host']

host=config.get('MysqlDB','host') (str格式)

sport=cfg.getint('MysqlDB','sport') (int格式)

  



posted @ 2019-12-20 16:16  青色蔷薇  阅读(675)  评论(0编辑  收藏  举报