你好,我的问题与optparse python。int或long在十六进制python optparse?
它是关于optparse的默认选项值,我将它表示为十六进制,但在转换为int或long时不起作用,如optparse python所定义。
http://docs.python.org/library/optparse.html#standard-option-types
,这是我的一小段代码:
parser.add_option("-o", "--offset",
dest="offset_pattern",
default=0x41306141,
type="long",
action="store",
metavar="HEX",
help="define the offset will be found [default : %default]")
但它仍然给我这个样子,即使我使用int或者只要数据类型的错误
Traceback (most recent call last):
File "./pattern.py", line 155, in <module>
main()
File "./pattern.py", line 151, in main
proxyengine.parseoption()
File "./pattern.py", line 132, in parseoption
(options, args) = parser.parse_args()
File "/usr/lib/python2.6/optparse.py", line 1365, in parse_args
values = self.get_default_values()
File "/usr/lib/python2.6/optparse.py", line 1310, in get_default_values
defaults[option.dest] = option.check_value(opt_str, default)
File "/usr/lib/python2.6/optparse.py", line 756, in check_value
return checker(self, opt, value)
File "/usr/lib/python2.6/optparse.py", line 416, in check_builtin
_("option %s: invalid %s value: %r") % (opt, what, value))
optparse.OptionValueError: option --offset: invalid long integer value: 'buff'
而这
Traceback (most recent call last):
File "./pattern.py", line 155, in <module>
main()
File "./pattern.py", line 151, in main
proxyengine.parseoption()
File "./pattern.py", line 132, in parseoption
(options, args) = parser.parse_args()
File "/usr/lib/python2.6/optparse.py", line 1365, in parse_args
values = self.get_default_values()
File "/usr/lib/python2.6/optparse.py", line 1310, in get_default_values
defaults[option.dest] = option.check_value(opt_str, default)
File "/usr/lib/python2.6/optparse.py", line 756, in check_value
return checker(self, opt, value)
File "/usr/lib/python2.6/optparse.py", line 416, in check_builtin
_("option %s: invalid %s value: %r") % (opt, what, value))
optparse.OptionValueError: option --offset: invalid integer value: 'buff'
有帮助吗? 谢谢, 枪支。
[编辑] 我删除此代码和程序工作
parser.add_option("-n", "--variable",
dest="offset_pattern",
default="buff",
type="string",
action="store",
metavar="STR",
help="define variable buffer name will be create [default : %default]")
任何回答,为什么我必须消除对工作程序的代码?
我不认为这个错误出现在您发布的代码中。 – Omnifarious 2011-04-22 16:10:41
该代码适用于我。 – interjay 2011-04-22 16:12:44
什么是“buff”?你怎么调用你的脚本? – zxt 2011-04-22 16:13:51