gpt4 book ai didi

python 字符串列表列出 ast.listeral_eval

转载 作者:太空宇宙 更新时间:2023-11-03 12:22:06 25 4
gpt4 key购买 nike

<分区>

>>> import ast
>>> string = '[Small, Medium, Large, X-Large]'
>>> print string
[Small, Medium, Large, X-Large]
>>> string = ast.literal_eval(string)
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
string = ast.literal_eval(string)
File "C:\Python27\lib\ast.py", line 80, in literal_eval
return _convert(node_or_string)
File "C:\Python27\lib\ast.py", line 60, in _convert
return list(map(_convert, node.elts))
File "C:\Python27\lib\ast.py", line 79, in _convert
raise ValueError('malformed string')
ValueError: malformed string

如何修复?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com