Python Parse CSV Correctly

后端 未结 5 993
自闭症患者
自闭症患者 2020-11-28 11:48

I am very new to Python. I want to parse a csv file such that it will recognize quoted values - for example

1997,Ford,E350,\"Super, luxurious truck\"

5条回答
  •  被撕碎了的回忆
    2020-11-28 12:30

    You should use the csv module:

    import csv
    reader = csv.reader(['1997,Ford,E350,"Super, luxurious truck"'], skipinitialspace=True)
    for r in reader:
        print r
    

    output:

    ['1997', 'Ford', 'E350', 'Super, luxurious truck']
    

提交回复
热议问题