网络编程
位置:首页>> 网络编程>> Python编程>> python读取ini配置文件过程示范

python读取ini配置文件过程示范

作者:青色蔷薇  发布时间:2023-07-02 01:18:36 

标签:python,读取,ini,配置,文件

这篇文章主要介绍了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

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com