Some Python Examples
← prev | next →     Top-level ToC     /csv.html     (printable version)
import csv, os

# Read a csv file, line-by-line.
with open('in.csv', newline='') as f:
    reader = csv.reader(f)
    for row in reader:
        # Each row is a list of strings.

# Write a csv file.
lol = [
    ['size', 'color', 'angle'],
    ['5', 'green', '45'],
    ['6', 'orange', '50'],
with open('out.csv', 'w', newline='') as f:
    # You need this to get a regular non-DOS text file.
    writer = csv.writer(f, lineterminator=os.linesep)