import csv import sys print "Write a cvs file:" data = [ ("And Now For Something Completely Different", 1971, "Ian MacNaughton"), ("Monty Python And The Holy Grail", 1975, "Terry Gilliam, Terry Jones"), ("Monty Python's Life Of Brian", 1979, "Terry Jones"), ("Monty Python Live At The Hollywood Bowl", 1982, "Terry Hughes"), ("Monty Python's The Meaning Of Life", 1983, "Terry Jones") ] f = file("some.csv", "w") # This is absolutely necessary so that the file will actually be written while the Python shell is open. stuff = csv.writer(f) for item in data: stuff.writerow(item) f.close() print "\nRead the cvs file and print the list of rows:" f = file("some.csv", 'r') stuff = csv.reader(f) for r in stuff : print r f.close() print "\nRead the cvs file and print a column:" f = file("some.csv", 'r') stuff = csv.reader(f) for r in stuff : print r[1] f.close() print "\nRead the cvs file and print the identified columns:" f = file("some.csv", 'r') stuff = csv.reader(f) for title, year, director in stuff : print title, year, director f.close() print "\nRead the cvs file and try the .next() function twice:" f = file("some.csv", 'r') stuff = csv.reader(f) print stuff.next() print stuff.next()