在使用shlex.split()时,如何保留“带空格的值”周围的引号?
s = "SOME_VAR=\"value with spaces\" VAR2=value2"
shlex.split(s)
['SOME_VAR=value with spaces', 'VAR2=value2']谢谢
发布于 2016-12-08 04:09:26
您对Python工具的选择可能不是最佳的。
这样如何:
$ cat /tmp/tmp.py
import csv
import StringIO
s = "SOME_VAR=\"value with spaces\" VAR2=value2"
reader = csv.reader(StringIO.StringIO(s), csv.excel)
for i in reader:
print i
$ python /tmp/tmp.py
['SOME_VAR="value with spaces" VAR2=value2']https://stackoverflow.com/questions/41025333
复制相似问题