linux - Optparse and sys.argv - Python -
i've written python script, accepts input via optparse
module of python. , take input sys.argv
well.
when utilize either of them, programme works correctly. example:
python dperf.py -m 1 -c 2 -n 3 python dperf.py foobar
however, not when give input in manner.
python dperf.py foobar -m 1 -c 2 -n 3
is there error in way using sys.argv
?
parser = optparse.optionparser() #migration parser.add_option("-m", type="float", dest="migr") #collection parser.add_option("-c", type="float", dest="coll") #num of lines read parser.add_option("-n", type="float", dest="fileread") (options, args) = parser.parse_args() ti = options.migr colle = options.coll linereadfiles = options.fileread apps = sys.argv[1:]
if parse options via parse_args()
of optionparser
, not utilize sys.argv
straight returned args
instead should contain parts not parsed optionparser
.
for illustration in code replace
apps = sys.argv[1:]
by
apps = args
(or scrap apps
, go on args
).
python linux
No comments:
Post a Comment