Python Parse CSV Correctly

后端 未结 5 1005
自闭症患者
自闭症患者 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 have to define the doublequote as the quotechar whithin the csv.reader() statement:

    >>> with open(r'') as csv_file:
    ...     reader = csv.reader(csv_file, delimiter=',', quotechar='"')
    ...     print(reader.next())
    ... 
    ['1997', 'Ford', 'E350', 'Super, luxurious truck']
    >>> 
    

提交回复
热议问题