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

Dave Angel davea at ieee.org
Thu Apr 16 11:00:47 EDT 2009


sapsi wrote:
> Hello,
> Im using optparse and python 2.6 to parse some options, my commandline
> looks like
>
> prog [options] start|stop extra-args-i-will-pas-on
>
> The options are --b --c --d
>
> The extra options are varied are are passed onto another program e.g --
> quiet --no-command , my program doesnt care what these are but instead
> passes them onto another program.
>
> I know these will always follow start|stop.
>
> However optparse tries to process them and throws an exception - how
> can i prevent this without placing all the extra-args in quotes.
>
> Thank you
> 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.




More information about the Python-list mailing list