The Problem is that argparse can't recognize the argument with tags like --argument-option
Example code
import argparse
parser = argparse.ArgumentParser(description="Help")
parser.add_argument("-a", "--argument-option", metavar="", help="Help")
args = parser.parse_args()
option = args.argument-option
print(option)
Results in AttributeError: 'Namespace' object has no attribute 'argument'
I tried few codes and was able to find a solution by changing -a
to --a
:-
import argparse
parser = argparse.ArgumentParser(description="Help")
parser.add_argument("--a", "--argument-option", metavar="", help="") # change here
args = parser.parse_args()
option = args.a # And here
print(option)
But if possible i would like to shorten the optional argument --argument-option
to older -a
and not --a