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="" 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.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to