How to convert tuple in string to tuple object?
Question: In Python 2.7, I have the following string:

    
    
    "((1, u'Central Plant 1', u'http://egauge.com/'),
    (2, u'Central Plant 2', u'http://egauge2.com/'))"
    

**How can I convert this string back to tuples?** I've tried to use `split` a
few times but it's very messy and makes a list instead.

Desired output:

    
    
    ((1, 'Central Plant 1', 'http://egauge.com/'),
    (2, 'Central Plant 2', 'http://egauge2.com/'))
    

Thanks for the help in advance!


Answer: You should use the `literal_eval` method from the `ast` module which you can
read more about
[**here**](http://docs.python.org/2/library/ast.html#ast.literal_eval).

    
    
    >>> import ast
    >>> s = "((1, u'Central Plant 1', u'http://egauge.com/'),(2, u'Central Plant 2', u'http://egauge2.com/'))"
    >>> ast.literal_eval(s)
    ((1, u'Central Plant 1', u'http://egauge.com/'), (2, u'Central Plant 2', u'http://egauge2.com/'))
    

