How to a turn a list of strings into complex numbers in python?
<p>I'm trying to write code which imports and exports lists of complex numbers in Python. So far I'm attempting this using the csv module. I've exported the data to a file using:</p>

<pre><code>spamWriter = csv.writer(open('data.csv', 'wb')
spamWriter.writerow(complex_data)
</code></pre>

<p>Where complexe data is a list numbers generated by the complex(re,im) funtion. Ex:</p>

<pre><code>print complex_data
[(37470-880j),(35093-791j),(33920-981j),(28579-789j),(48002-574j),(46607-2317j),(42353-1557j),(45166-2520j),(45594-232j),(41149+561j)]
</code></pre>

<p>To then import this at a later time, I try the following:</p>

<pre><code>mycsv = csv.reader(open('data.csv', 'rb'))
out = list(mycsv)
print out
[['(37470-880j)','(35093-791j)','(33920-981j)','(28579-789j)','(48002-574j)','(46607-2317j)','(42353-1557j)','(45166-2520j)','(45594-232j)','(41149+561j)']]
</code></pre>

<p>(Note that this is a list of lists, I just happened to use only one row for the example.)</p>

<p>I now need to turn this into complexe numbers rather than strings. I think there should be a way to do this with mapping as in <a href="http://stackoverflow.com/questions/642154/how-to-convert-strings-into-integers-in-python">this question</a>, but I couldn't figure out how to make it work. Any help would be appreciated!</p>

<p>Alternatively, if there's any easier way to import/export complex-valued data that I don't know of, I'd be happy to try something else entirely. </p>
