Validating positional arguments in optparse

Robert Kern robert.kern at
Fri Oct 23 18:03:10 CEST 2009

On 2009-10-23 05:54 AM, Filip Gruszczyński wrote:
>> That being said, I still stick with optparse. I prefer the dogmatic
>> interface that makes all my exe use the exact same (POSIX) convention. I
>> really don't care about writing /file instead of --file
> I would like to keep POSIX convention too, but just wanted
> OptionParser to do the dirty work of checking that arguments are all
> right for me and wanted to know the reason, it doesn't.
> I guess I should write a subclass, which would do just that.

If you don't want to allow /file, just don't use it. argparse's default is to 
only allow --options and not /options. You can configure it to do otherwise, but 
you are in complete control. Your programs will all follow the same convention.

I highly, highly recommend argparse over optparse.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

More information about the Python-list mailing list