Split by comma and how to exclude comma from quotes in split … Python

后端 未结 8 1962
长情又很酷
长情又很酷 2020-12-16 13:28

python 2.7 code

cStr = \'\"aaaa\",\"bbbb\",\"ccc,ffffd\"\' 

newStr = cStr.split(\',\')

print newStr 

# result : [\'\"aaaa\"\',\'\"bbbb\"\',\'\"ccc\',\'ffffd\         


        
8条回答
  •  爱一瞬间的悲伤
    2020-12-16 13:43

    Try to use CSV.

    import csv
    cStr = '"aaaa","bbbb","ccc,ffffd"'
    newStr = [ '"{}"'.format(x) for x in list(csv.reader([cStr], delimiter=',', quotechar='"'))[0] ]
    
    print newStr
    

    Check Python parse CSV ignoring comma with double-quotes

提交回复
热议问题