编程时,很多参数通常都存放在配置文件中,可以方便的更改。
python提供了方便的读取配置文件的方式。
config.ini文件内容:
[Time]
t_sample:0.02
[str]
hello:world
from ConfigParser import ConfigParser
CONFIGFILE = "config.ini"
config = ConfigParser()
config.read(CONFIGFILE)
x = config.getfloat("Time","t_sample")
y = config.get("str","hello")