[英]Converting String of Tuple into Tuple
How to convert a string in Python into a Tuple without splitting the words into characters?如何在不将单词拆分为字符的情况下将 Python 中的字符串转换为元组?
String: "('name','value')"
字符串: "('name','value')"
Expected Output: ('name', 'value')
预期输出:( ('name', 'value')
you can use module ast
你可以使用模块ast
>>> a = "('name','value')"
>>> import ast
>>> ast.literal_eval(a)
('name', 'value')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.