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'