title: Accepting a dictionary as an argument with argparse and python
body: <p>I'm trying to accept an argument of type=dict with argparse but no matter the input it gives an error of invalid dict value.</p>
  
  <pre><code>#!/usr/bin/env python
  
  import argparse
  
  MYDICT = {'key': 'value'}
  
  parser = argparse.ArgumentParser()
  parser.add_argument("-m", "--mydict", action="store",
                      required=False, type=dict,
                      default=MYDICT)
  
  args = parser.parse_args()
  
  print args.mydict
  </code></pre>
  
  <p>This is what  happens when I try and pass a dictionary to the script</p>
  
  <pre><code>./argp.py -m "{'key1': 'value1'}"
  usage: argp.py [-h] [-m MYDICT]
  argp.py: error: argument -m/--mydict: invalid dict value: "{'key1': 'value1'}"
  </code></pre>
  
  <p>Looking at the documents I would think that this would be possible.</p>
  
  <p><a href="http://docs.python.org/dev/library/argparse.html">http://docs.python.org/dev/library/argparse.html</a></p>
  
  <p>“Any object that supports the in operator can be passed as the choices value, so dict objects, set objects, custom containers, etc. are all supported.”</p>