python读取ini配置文件过程示范
作者:青色蔷薇 时间:2023-07-02 01:18:36
这篇文章主要介绍了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格式)
来源:https://www.cnblogs.com/cyanrose/p/12073731.html
标签:python,读取,ini,配置,文件
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python探索之pLSA实现代码
2022-01-03 11:30:28
python基础之编码规范总结
2021-04-17 06:13:26
在VSCode中搭建Python开发环境并进行调试
2021-09-20 23:19:13
![](https://img.aspxhome.com/file/2023/6/114676_0s.png)
如何使用Docker恢复Mysql8备份的Data数据
2024-01-14 20:07:04
![](https://img.aspxhome.com/file/2023/7/127957_0s.jpg)
python 详解如何使用GPU大幅提高效率
2023-08-24 19:45:46
![](https://img.aspxhome.com/file/2023/0/62550_0s.png)
Go语言工程实践单元测试基准测试示例详解
2024-03-11 17:00:08
![](https://img.aspxhome.com/file/2023/0/107380_0s.jpg)
由浅入深学习TensorFlow MNIST 数据集
2021-06-04 23:57:52
![](https://img.aspxhome.com/file/2023/0/84130_0s.png)
如何基于python生成list的所有的子集
2021-09-24 07:31:31
基于JS实现经典的井字棋游戏
2024-04-28 09:51:10
![](https://img.aspxhome.com/file/2023/8/132728_0s.png)
Python的pdfplumber库将pdf转为图片的实现
2021-08-31 20:43:27
![](https://img.aspxhome.com/file/2023/3/115523_0s.png)
HTML5 JS压缩图片并获取图片BASE64编码上传
2024-04-17 10:25:44
详解TensorFlow训练网络两种方式
2021-06-24 00:18:23
selenium+python自动化测试之使用webdriver操作浏览器的方法
2023-06-28 03:04:47
14 个Python小游戏 源码分享
2023-09-22 15:12:28
![](https://img.aspxhome.com/file/2023/9/76079_0s.gif)
SQL Server游标的介绍与使用
2024-01-21 10:02:25
Python3自定义http/https请求拦截mitmproxy脚本实例
2021-04-13 15:33:01
![](https://img.aspxhome.com/file/2023/3/63613_0s.jpg)
javascript 数组去重复(在线去重工具)
2024-04-16 09:14:51
SQL Server中查询结果超出了查询时间范围解决方法
2024-01-18 04:05:54
![](https://img.aspxhome.com/file/2023/0/119220_0s.png)
SQL Server 总结复习 (二)
2012-10-07 10:35:00
JupyterNotebook设置Python环境的方法步骤
2023-01-15 12:22:14
![](https://img.aspxhome.com/file/2023/6/135176_0s.png)