# Program to print file contents with line number prepended to each line # Matt Bishop, Apr. 17, 2009 # for ECS 10 Spring 2009 # def main(): # get file name fname = raw_input("Please enter the name of the file to print:"); # # line by line, adding line numbers as we go # infile = open(fname, 'r'); # initialize line counter lineno = 1; # for each line in the file ... for line in infile: # print the line number, then the line print "%6d." % lineno, print line, lineno = lineno + 1; # all done! infile.close(); main();