I have a config file db.py . It looks as:
user="user"
password="pass"
charset="utf8"
collation="utf8_bin"
host="localhost"
db="dbname"
I'm trying the following code:
from tornado.options import options, parse_config_file
parse_config_file('db.py')
print options.charset
I'm getting the following error:
Traceback (most recent call last):
File "", line 5, in <module>
print options.charset
File "/usr/lib/python2.7/dist-packages/tornado/options.py", line 97, in __getattr__
raise AttributeError("Unrecognized option %r" % name)
AttributeError: Unrecognized option 'charset'
Can someone tell me if I'm doing something wrong? Thanks.
As answered by @JohnZwinck, I used the following:
from tornado.options import define, options, parse_config_file
define("charset", type=str)
parse_config_file('db.py')
print options.charset
and it works.
您需要在解析和使用它们之前“ 定义 ”您的选项。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.