新接触 Tornado,在使用 tornado.options.parse_config_file 读取配置文件时,发现直接调用会出错,非要先 define 一下,才能正常读取配置文件,比如:
> 配置文件(config.cfg)的内容为:
dbhost="localhost"
> 使用如下代码会出错:
tornado.options.parse_config_file("config.cfg")
print options.dbhost
> 使用如下代码反而正常读取配置文件的内容(default的值随便写,会被配置文件的内容覆盖):
define("dbhost", default="xxxxx")
tornado.options.parse_config_file("config.cfg")
print options.dbhost
> 难道在设计上,配置文件只是为了切换不同环境,默认配置还需要 define 在代码里?请问如果不用 define 而直接读取配置文件的内容?
> 配置文件(config.cfg)的内容为:
dbhost="localhost"
> 使用如下代码会出错:
tornado.options.parse_config_file("config.cfg")
print options.dbhost
> 使用如下代码反而正常读取配置文件的内容(default的值随便写,会被配置文件的内容覆盖):
define("dbhost", default="xxxxx")
tornado.options.parse_config_file("config.cfg")
print options.dbhost
> 难道在设计上,配置文件只是为了切换不同环境,默认配置还需要 define 在代码里?请问如果不用 define 而直接读取配置文件的内容?