#!/usr/bin/env python # assuming the file fits into memory, this program will # display the program and number the lines. # # It will also write out a copy of the file with the # hardcoded name in OUT_FILENAME # # written by e.bonakdarian dec 2009 # from random import randrange OUT_FILENAME = 'numbered.txt' filename = raw_input('Enter the filename: ') inf = open(filename) # open input file text = inf.readlines() inf.close() # done with file print ' .. processing ... ' # open output file now outf = open(OUT_FILENAME, 'w') # open output file count = 1 for line in text: print >> outf, '%03d : %s' % (count, line), count += 1 outf.close() # done with output file print 'Wrote output to file "%s".' % OUT_FILENAME raw_input('\n to exit.')