chanchal pardeshi chanchal pardeshi - 1 year ago 100
Python Question

Converting String of Tuple into Tuple

How to convert a string in Python into a Tuple without splitting the words into characters?



Expected Output:
('name', 'value')

Answer Source

you can use module ast

>>> a = "('name','value')"
>>> import ast
>>> ast.literal_eval(a)
('name', 'value')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download