Show all lines
This very simple program will print all lines read from a file:
# the open function returns a file object cars_file = open('2006_FE_Guide_14-Nov-2005_download.csv', 'rb') # loop over each line of the file for line in cars_file: print line # releases the file object cars_file.close()
It has the very same for loop we have been using. Only that now in instead of loop over a list in memory it will loop over a sequence of lines (the file) in disk.
You will notice this program has an inconvenient behavior: it is so fast that you can't read the lines.
Let's take care of this next.