[Tutor] Two Questions...(i) Checking for None (ii) Making commandline arguments mutually exclusive
alan.gauld at btinternet.com
Sat Nov 4 14:30:45 CET 2006
"Asrarahmed Kadri" <ajkadri at googlemail.com> wrote
> *-s <IP address> -D <start date> -n <no. of days> -t <start time>
> the first argument which is -s (for source) can be replaced by -d
> 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
I think you will need to hard-code the logic.
Check to see which options have been defined and if more than one of
the optional options exists print an error.
if a and (b or c or d) or (b and (c or d)) or (c and d):
Another way is to count the values:
if len([val for val in [a,b,c,d] if val != None]) > 1:
> My second question is about chekcing for None type. The issue is
> 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.
if x == None
As simple as that.
More information about the Tutor