我需要拆分以下字符串:
str1 = "0020 04,5",3
预期输出为:
['0020 04,5', '3']
我试过的是
print [p for p in re.split('(|".+?"|,|)', a) if p.strip()]
答案 0 :(得分:1)
您可以将字符串转换为列表:
str1 = ['"0020 04,5",3']
并使用csv
模块:
>>> from csv import reader
>>> for line in reader(str1):
... print line
...
['0020 04,5', '3']
答案 1 :(得分:0)
a=[]
for x in str:
a.append(x)
print a
['0020 04,5', 3]
另一种方式:
[a.append(x) for x in str]