putting int/float from file into a dictionary
<p>I like to put some values from a csv file into a dict. An example is:</p>

<pre><code>TYPE, Weldline

Diam, 5.0

Num of Elems, 4
</code></pre>

<p>and I end up after reading into a dictionary (for later use in an API) in:</p>

<pre><code> {'TYPE':'Weldline' , 'Diam':'5.0','Num of Elems':'4'}
</code></pre>

<p>Since the API expects a dictionary i provided all the necessary keywords like 'TYPE', 'Diam', ... according to the API doc.</p>

<p>The problem I have is, that the API expects a float for <code>Diam</code> and an integer for <code>Num of Elems</code></p>

<p>Since I have a large number of entries: is there an simple automatic way for string conversion into float or int?
Or do I have to write something on my own?</p>

<p>Also try this it seems more simple.</p>

<pre><code>import csv,ast
    with open('file.csv', mode='r') as file:
    reader = csv.reader(file)
    mydict = {rows[0]:ast.literal_eval(rows[1]) for rows in reader}
print mydict
</code></pre>

python type-conversion