I'm using argparse
for my Python CLI as follows:
import argparse
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--myarg', type=str, help="Dummy arg")
args = parser.parse_args()
# access with dot notation
print(args.myarg)
This works fine. However, I now want to add an argument called --continue
. Trying to access the arg with args.continue
gives me a syntax error.
Is there any other way to access CLI args other than the dot notation? I tried dict-like access args['continue']
but that gives me TypeError: 'Namespace' object is not subscriptable
.
Do I really have to think of another CLI arg name?