配置文件最好选一种标准化的格式,比如 ini, json, yaml, 再用标准化的方式去读取(而非自己去按行读,按等号分割),这样就优雅了吧。
fy
2016-05-19 19:26:49 +08:00
dict([x[:-1].split('=') for x in f.readlines()])
tongle
2016-05-19 19:27:36 +08:00
ConfigParser 也许你需要这个
imn1
2016-05-19 19:28:45 +08:00
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.