配置文件最好选一种标准化的格式,比如 ini, json, yaml, 再用标准化的方式去读取(而非自己去按行读,按等号分割),这样就优雅了吧。
fy
2016 年 5 月 19 日
dict([x[:-1].split('=') for x in f.readlines()])
tongle
2016 年 5 月 19 日
ConfigParser 也许你需要这个
imn1
2016 年 5 月 19 日
configparser — Configuration file parser
This module provides the ConfigParser class which implements a basic configuration language which provides a structure similar to what ’ s found in Microsoft Windows INI files. You can use this to write Python programs which can be customized by end users easily.