How do I split a line by commas, but ignore commas within quotes Python [duplicate]

If you want to read lines from a CSV file, use Python’s csv module from the standard library, which will handle the quoted comma separated values.

Example

# cat test.py
import csv
with open('some.csv') as f:
    reader = csv.reader(f)
    for row in reader:
        print(row)
# cat some.csv
"114111","Planes,Trains,and Automobiles","50","BOOK"
# python test.py

['114111', 'Planes,Trains,and Automobiles', '50', 'BOOK']
[]

Leave a Comment