python 读写ini文件 设置保存与读取
import configparser,sys cf = configparser.ConfigParser() #写INI def xini(): executor_url = "100" session_id = "6666" cf.add_section("ssh") cf.set("ssh","executor_url",executor_url) cf.set("ssh","session_id",session_id) cf.write(open("my.ini","w")) sys.exit(0) #读ini文件 ac=cf.read("my.ini") executor_url = cf.get("ssh","executor_url") session_id = cf.get("ssh","session_id") print(executor_url,session_id) ##>>> cf.items("ssh") ##[('executor_url', '100'), ('session_id', '6666')] ##>>> cf.getint("db","port")读取数值