#!/usr/bin/env python
import optparse
p = optparse.OptionParser()
p.add_option("-o", action="store", dest="outfile")
p.add_option("-d", action="store_true", dest="debugflag")
p.set_defaults(debugflag=True)
opts,args = p.parse_args()
print opts, " ", args
print opts.outfile, opts.debugflag
输出:
$ ./optparseexample.py -o myfile -d
{'outfile': 'myfile', 'debugflag': True} []
myfile True
$ ./optparseexample.py -o myfile
{'outfile': 'myfile', 'debugflag': True} []
myfile True
问题:
如何将debugflag的默认值从True
切换到False
?你知道吗
那么您应该使用
action=store_false
。你知道吗在问之前请先阅读documentation。你知道吗
相关问题 更多 >
编程相关推荐