python读取ini文件

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:UsersAdministratorDesktopPython源码config.ini
666qq.com

  

原文地址:https://www.cnblogs.com/jieliu8080/p/10656728.html