最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python如何读取ini配置文件 python读取ini配置文件代码示例
时间:2019-12-23 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下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格式)
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27