parsing a dictionary from file in python using argparse?
<p>I have been using a file containing variables as input for a program, which is then imported into the main program at runtime.  I am moving this system to using argparse reading the input values from a file. One of the current input variables is a list of dictionaries, with each dictionary providing settings for a given calculation. </p>

<pre><code>CalculationVals=[{'startx':0,'starty':0,'endx':10, 'endy':10}, {'startx':1,'starty':1,'endx':12, 'endy':12}]
</code></pre>

<p>and then in the main part of the program, the individual CalculationVals are looped over.  Is there a way to read this using argparse, or a better way to provide this input using an argparse method?  Not relying on additional packages is advantageous here.</p>

<p>That is not what argparse is for. It is for parsing command line arguments, not config files.</p>

<p>It looks like your config is in JSON and unless you do something extremely weird and heavily abuse the library, argparse does not know how to parse JSON. So to understand the parameters you'd need to <code>import json</code> anyway. At which point the easiest (and most efficient) thing to do would be</p>

<pre><code>import json

with open('/your/config/file', 'r') as f:
    config = json.loads(f.read())
</code></pre>

python argparse