csv Module
noun
say it: “SEE-ess-VEE MOJ-ool” /ˌsiɛsˈvi ˈmɑdʒul/
Python's built-in module for reading and writing CSV files, the plain-text tables that spreadsheet apps can open and save.
What is the csv module?
The csv module is Python's built-in module for CSV files. csv.DictReader reads each row as a dictionary named by
the header row, and csv.writer and csv.DictWriter write rows back out.
import csv
with open("runs.csv", newline="") as file:
for row in csv.DictReader(file):
print(row["runner"], row["miles"])
# Ana 3.1
# Ben 5.0
In a sentence
- “With the csv module, a name with a comma in it stays in one column.”
- “The running club's script uses the csv module to read every runner's miles.”
Level: Journeyman · More Python terms at this level
Updated