python 配置文件

python 配置文件
目录python 读取配置文件config.ini[database] host localhost port 3306 user root [app] debug true tikz_url http://39.97.230.23:8000/generatepython 读取配置文件import configparser import sys import os current_dir os.path.dirname(os.path.abspath(__file__)) os.chdir(current_dir) print(current_dir, current_dir) config configparser.ConfigParser() config.read(current_dir/config.ini) tikz_url config.get(app, tikz_url, fallbackhttp://localhost:8080) max_retries config.getint(app, max_retries, fallback3) # 浮点数 timeout config.getfloat(app, timeout, fallback30.0) scale config.getfloat(app, scale, fallback1.5) # 布尔值支持 yes/no, true/false, on/off, 1/0 debug config.getboolean(app, debug, fallbackFalse)