python - How to convert tuple in string to tuple object? -


in python 2.7, have following string:

"((1, u'central plant 1', u'http://egauge.com/'), (2, u'central plant 2', u'http://egauge2.com/'))" 

how can convert string tuples? i've tried use split few times it's messy , makes list instead.

desired output:

((1, 'central plant 1', 'http://egauge.com/'), (2, 'central plant 2', 'http://egauge2.com/')) 

thanks in advance!

you should use literal_eval method ast module can read more here.

>>> 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/')) 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -