Skip to content Skip to sidebar Skip to footer

Separate Fields By Comma And Quotes In Python?

I'm trying to separate this csv file into a 2D list. The problem with my code currently is that it cuts off a few fields on lines with quotes in the data. There are quotes there to

Solution 1:

If you're trying to load a CSV into a list then your entire code to do so is:

import csv

with open(sys.argv[1]) asdata:
    dataL = list(csv.reader(data))

If your example data is your input data, then it needs other work before hand..., eg:

dataL = [rowforrowin csv.reader(data) if row[0].startswith('Grand Total for')]

Post a Comment for "Separate Fields By Comma And Quotes In Python?"