12.20.5 Examples

Python PEP

12.20.5 Examples

The ``Hello, world'' of csv reading is

import csv
reader = csv.reader(open("some.csv", "rb"))
for row in reader:
    print row

To print just the first and last columns of each row try

import csv
reader = csv.reader(open("some.csv", "rb"))
for row in reader:
    print row[0], row[-1]

The corresponding simplest possible writing example is

import csv
writer = csv.writer(open("some.csv", "wb"))
for row in someiterable:
    writer.writerow(row)

See About this document... for information on suggesting changes.