Created
May 4, 2013 07:09
-
-
Save felinx/5516568 to your computer and use it in GitHub Desktop.
tornado.options.options don't parse default value automatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
# Copyright (c) 2013 feilong.me All rights reserved. | |
# | |
# @author: Felinx Lee <[email protected]> | |
# Created on May 4, 2013 | |
# | |
""" | |
tornado.options.options don't parse default value automatically, sometimes, | |
the option's value is not the same as what we expected. | |
For example: | |
file: | |
test_options.py | |
run: | |
python test_options.py --addresses=127.0.0.1,192.168.1.1 --age=18 | |
output: | |
default age: 10 <type 'str'> | |
default addresses: 127.0.0.1,192.168.1.1 <type 'str'> | |
parsed age: 18 <type 'int'> | |
parsed addresses: ['127.0.0.1', '192.168.1.1'] <type 'list'> | |
""" | |
from tornado.options import options, define | |
define("age", default="10", type=int) | |
define("addresses", default="127.0.0.1,192.168.1.1", type=str, multiple=True) | |
print "default age: ", options.age, type(options.age) | |
print "default addresses: ", options.addresses, type(options.addresses) | |
options.parse_command_line() | |
print "parsed age: ", options.age, type(options.age) | |
print "parsed addresses: ", options.addresses, type(options.addresses) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment