import configparser import os config=configparser.ConfigParser()#创建config对象 file_path=os.path.dirname(os.path.abspath(‘.‘))+‘\Python源码\config.ini‘#读取文件父目录 config.read(file_path) sender=config.get(‘sender‘,‘sender‘)#读取ini配置文件中sender项中的sender值 print(file_path) print(sender)
config.ini文件:
[sender] sender = 666qq.com [receiver] receiver =8888qq.com
run结果:
C:\Users\Administrator\Desktop\Python源码\config.ini 666qq.com
原文地址:https://www.cnblogs.com/jieliu8080/p/10656728.html
时间: 2024-10-31 21:20:06