I've read this http://docs.python.org/release/2.6.2/library/optparse.html
But I'm not so clear how to make an option to be required in optparse?
I've tried to set "required=1" but I got an error:
invalid keyword arguments: required
I want to make my script require --file
option to be input by users. I know that the action
keyword gives you error when you don't supply value to --file
whose action="store_true"
.
I would use argparse library that has this functionality embedded:
argparse reference
On the help message of each required variable Im writting a '[REQUIRED]' string at the beggining, to tag it to be parsed later, then I can simply use this function to wrap it around:
Since
if not x
doesn't work for some(negative,zero) parameters,and to prevent lots of if tests, i preferr something like this: