optparse question, passing unknown flags to subprocess

J

Joseph Garvin

I'm working on a python script that takes several command line flags,
currently parsed by hand. I'd like to change the script to parse them
with OptionParser from the optparse module. However, currently the
script invokes a subprocess, and any flags the script doesn't
understand it assumes are meant to be passed to the subprocess. But if
I switch to using OptionParser, any options I haven't added to my
parser will cause an error, instead of it ignoring those and letting
me pass them onto the subprocess.

What's the best/most-pythonic way to handle this? I could subclass
OptionParser and override its exit() and error() methods as suggested
by the docs (http://www.python.org/doc/2.4/lib/optparse-how-optik-handles-errors.html)
and have them do nothing, but there are some errors I probably don't
want to ignore (like if the user tries to pass a string to a known
flag that takes an int).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top