Passing all extra commandline arguments to python program, Optparse raises exception

Robert Kern robert.kern at
Tue Apr 21 21:59:57 CEST 2009

On 2009-04-16 19:32, Saptarshi wrote:
>>> Saptarshi
>> Preprocess the sys.args before calling optparse.
>> Simply search sys.args for the string "start" and the string "stop", and
>> note whichever comes first.  Then use slice operators to peel the extra
>> arguments off of sys.args.
> Thanks, i implemented your logic. I thought there was a Optparse
> feature to handle this.

There is:

   parser.allow_interspersed_args = False

This means that as soon as the parser hits start|stop, it assumes that 
everything following it is an argument and not an option that it needs to try to 

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