How can I convert a vector in string form to tuple form with each vector component being a tuple element?
<p>I'm writing a Python script to parse an XML file. When I get to the following part of the XML file,</p>

<pre><code>      &lt;H.1&gt;
      (1.00000000000000, 0.000000000000000E+000)
      &lt;/H.1&gt;
</code></pre>

<p>the script uses the following to parse the text</p>

<pre><code>    H1 = H.find('H.1')
    tokens = H1.text.split()
</code></pre>

<p>This produces a list named tokens with the single string element '(1.00000000000000,0.000000000000000E+000)'. How can I make it so that what is produced is a tuple with first element 1.00000000000000 and second element 0.000000000000000E+000? Or, at least, how can I convert the vector from string form to two-element tuple form?</p>

<p>You can use <a href="https://docs.python.org/3/library/ast.html#ast.literal_eval" rel="nofollow">literal_eval</a> from <a href="https://docs.python.org/3/library/ast.html" rel="nofollow">ast</a>:</p>

<pre><code>&gt;&gt;&gt; s = '(1.00000000000000,0.000000000000000E+000)'
&gt;&gt;&gt; from ast import literal_eval
&gt;&gt;&gt; t = literal_eval(s)
&gt;&gt;&gt; t
(1.0, 0.0)
&gt;&gt;&gt; type(t[0])
&lt;type 'float'&gt;
&gt;&gt;&gt; print(type(t))
&lt;type 'tuple'&gt;
</code></pre>

python xml list vector