I\'m trying to set up a dictionary as optional argument (using argparse); the following line is what I have so far:
parser.add_argument(\'-i\',\'--image\', t
Combining the type=
piece from @Edd and the ast.literal.eval
piece from @Bradley yields the most direct solution, IMO. It allows direct retrieval of the argval and even takes a (quoted) default value for the dict:
parser.add_argument('--params', '--p', help='dict of params ', type=ast.literal.eval, default="{'name': 'adam'}")
args = parser.parse_args()
python test.py --p "{'town': 'union'}"
note the quotes on the dict value. This quoting works on Windows and Linux (tested with [t]csh).
dict=args.params