chanchal pardeshi chanchal pardeshi - 2 months ago 6
Python Question

Converting String of Tuple into Tuple

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

String:

"('name','value')"


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

Answer

you can use module ast

>>> a = "('name','value')"
>>> import ast
>>> ast.literal_eval(a)
('name', 'value')
Comments