let optionparse.Optionparser ignore unknown command line switches.

News123 news1234 at free.fr
Sun Aug 1 07:27:00 EDT 2010


On 08/01/2010 01:08 PM, News123 wrote:
> I wondered, whether there's a simple/standard way to let
> the Optionparser just ignore unknown command line switches.
> 

In order to  illustrate, what I try to achieve:


import optparse
parser = optparse.OptionParser()
parser.add_option("-t","--test",dest="test",action="store_true")
argv=["tst.py","-t","--ignoreme_and_dont_fail"]
try:
    (options,args)=parser.parse_args(argv)
except:
    # due to --ignoreme_and_dont_fail
    # I will end up here and neither options nor
    # args will be populated
    print "parser error:"
# However I would love to be able to see here
# that options.test is true despite the
# error, that occurred afterwards
print "T",options.test




More information about the Python-list mailing list