csv.reader()
csv.reader() is a Python function in the CSV Module category. Returns a reader object that iterates over lines in a CSV file. The syntax is csv.reader(csvfile, dialect="excel", **fmtparams). Parameters: csvfile — file object. Returns: CSV reader iterator. A typical example: import csv
with open("data.csv") as f:
for row in csv.reader(f):
print(row) # ["col1", "col2", ...]. A close sibling is csv.writer(), which returns a writer object for writing rows to a CSV file. A close sibling is csv.DictReader(), which returns a reader that maps each row to a dict with field names as keys. A close sibling is csv.DictWriter(), which returns a writer that maps dicts to CSV rows using fieldnames. A close sibling is csv.writer.writerow(), which writes a single row to the CSV file (row is a sequence of values). More about this category: CSV file reading and writing — reader, writer, DictReader, DictWriter. For a broader walkthrough, read the CSV Module guide.