I like to convert in a Python script the following string:
mystring='(5,650),(235,650),(465,650),(695,650)'
to a list of tuples
mytuple=[(5,650),(235,650),(465,650),(695,650)]
such that
print mytuple[0]
yields:
(5,650)
I'd use ast.literal_eval
:
In [7]: ast.literal_eval('(5,650),(235,650),(465,650),(695,650)')
Out[7]: ((5, 650), (235, 650), (465, 650), (695, 650))
As seen above, this returns a tuple of tuples. If you want a list of tuples, simply apply list()
to the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With