[Tutor] Two Questions...(i) Checking for None (ii) Making command line arguments mutually exclusive
Asrarahmed Kadri
ajkadri at googlemail.com
Sat Nov 4 11:36:58 CET 2006
Hi Folks,
I am trying to build a program which takes the following command-line
arguments:
*-s <IP address> -D <start date> -n <no. of days> -t <start time> <end
time>*
the first argument which is -s (for source) can be replaced by -d (for
destination) or -o (for observer) or -r (for reporter). Now what I want is
to make sure that the user only supplies one of the options from the 4
alternatives.
I am using 'optparse' module. It has got a nice feature taht enables you to
give the option name, along with the variable-name to store the value of
that option. The syntax is as under:
from optparse import OptionParser
parser = OptionParser() # make an object of OptionParser
parser.add_option("-s", action="store", type="string", dest="source_ip" ) #
mapping argument to the value and storing it in souce_ip
My second question is about chekcing for None type. The issue is that
optionParser sets the value = None for all the options that are not
specified by the user. So suppose if the user doesnt specify -t, then time
would be set to None. How to check the None type.
TIA.
Regards,
Asrarahmed
--
To HIM you shall return.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061104/9a849935/attachment.html
More information about the Tutor
mailing list