使用shlex.split()时,如何在“带空格的值”周围保留引号?
s = "SOME_VAR=\"value with spaces\" VAR2=value2"
shlex.split(s)
['SOME_VAR=value with spaces', 'VAR2=value2']
谢谢
答案 0 :(得分:0)
您选择的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']