In [4]: import shlex
In [6]: text = """'This doesn''t work' 54e+5 15 .FALSE. 'Another example of "test"'"""
In [34]: [item.replace('\\"\\"',"''") for item in shlex.split(text.replace("''",'\\"\\"'))]
Out[34]: ["This doesn''t work", '54e+5', '15', '.FALSE.', 'Another example of "test"']
理想情况下,如果您控制文本是如何生成的,我会将文件写为CSV,并允许CSV模块正确地引用项目。然后再把它读回一个列表中就很容易了。在
但鉴于文本本身,如何:
相关问题 更多 >
编程相关推荐