I got some confusion in the python add_option
I write the code like this
parser.add_option("-u", "--uniqueness",
action="store_true", dest="uniqueness", default=False)
Later in the shell, I want to write something like:
if(the user input -u option):
do something
My question is, how can I write “the user input -u option” in python? I tried to use “if(parser.uniqueness)” however, this command doesn’t work. Btw I am using python 2.7.3 (just wonder if this command will be different from the command in python 3) thx
Firstly,
optparseis deprecated, so you should useargparse– but the logic will be similar.You need to do
args = parser.parse_args()somewhere first, and then check in this object with :