Home‎ > ‎

CSV Headers

posted Aug 3, 2012, 5:13 PM by Sophie Engle

The following code will read and use the header row in the faculty.csv file:

import csv

input_file = open("faculty.csv", "r")
reader = csv.reader(input_file)

# Reads a single line from the reader and saves it as the column headers.
headers = reader.next()

# Starts at the second row.
for row in reader:
    for i, value in enumerate(row):
        print "%s: %s" % (headers[i], value)
    print

input_file.close()

ċ
print_faculty_csv.py
(0k)
Sophie Engle,
Aug 3, 2012, 5:13 PM
Comments