option argument length

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sun Dec 4 16:54:00 EST 2005


In <mailman.1573.1133729565.18701.python-list at python.org>, Ritesh Raj
Sarraf wrote:

> My program uses mostly "option arguments" hence my len(args) value is always
> zero. I need to check if the user has passed the correct number of "option
> arguments". Something like:
> 
> (options,args) = parser.parse_args()
> 
> len(options) != 1 or len(options) > 2:
>         print "Incorrect number of arguments passed."
> 
> How do I accomplish it ?

Just insert an ``if`` in front of the condition and end the program with
``sys.exit()`` after the message.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list