python 配置文件操作模块 configobj
作者:互联网
- 安装模块
pip install configobj
配置文件内容:
[DEFAULT] appid = appkey =
- 读取配置文件
from configobj import ConfigObj config = ConfigObj("config.ini", encoding='utf-8')
appid = config['DEFAULT']['appid']
appkey = config['DEFAULT']['appkey']最好做个判断,如果节点不存在,程序就会报错
if 'DEFAULT' in config and 'appkey' in config['DEFAULT']: # 判断节点是否存在 if config['DEFAULT']['appkey'] != "": # 判断值是否为空 appkey = config['DEFAULT']['appkey'] else: appkey = 'xxxxxx' else: appkey = 'xxxxxx'
标签:configobj,appkey,配置文件,python,DEFAULT,appid,config 来源: https://www.cnblogs.com/jonah/p/15208539.html