I want to pass a dictionary on command line. The following code fails:
import json
import argparse
parser = argparse.ArgumentParser(description='Test Arg Parse')
parser.add_argument('-d', '--dict', type=dict, required=False)
variables = vars(parser.parse_args())
print json.dumps(variables)
When I'm running the program, it throws the following error:
C:\KTLO\bin>python TestProg.py -d "{'a':'b'}"
usage: TestProg.py [-h] [-d DICT]
TestProg.py: error: argument -d/--dict: invalid dict value: "{'a':'b'}"
Edit 1: Specifying 'json.loads' or 'dict' does not change the output and still it throws the error.