如何使用 Python 将以下字符串转换为数组(该字符串可能有无限数量的项目)?
'["Foo","Bar","Baz","Woo"]'
这绝对也是一个字符串表示形式。type()
gave:
<class 'str'>
我得到了它。
interestedin = request.POST.get('interestedIn')[1:-1].split(',')
interested = []
for element in interestedin:
interested.append(element[1:-1])
Where request.POST.get('interestedIn')
给了'["Foo","Bar","Baz","Woo"]'
字符串列表“事物”。
你可以这样做
import ast
list = '["Foo","Bar","Baz","Woo"]'
list = ast.literal_eval(list)
print list
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)