File: class/Workbook/Exercises/Lab8/ex7_8.txt

% cat cat.py
import sys, string

def lister(name):
    num = 0
    for line in open(name, 'r').readlines():
        num = num+1
        print '%04d) %s' % (num, string.upper(line)) ,

if __name__ == '__main__': lister(sys.argv[1])


% python cat.py cat.py
0001) IMPORT SYS, STRING
0002)
0003) DEF LISTER(NAME):
0004)     NUM = 0
0005)     FOR LINE IN OPEN(NAME, 'R').READLINES():
0006)         NUM = NUM+1
0007)         PRINT '%04D) %S' % (NUM, STRING.UPPER(LINE)) ,
0008)
0009) IF __NAME__ == '__MAIN__': LISTER(SYS.ARGV[1])


% python
>>> import cat
>>> cat.lister('cat.py')




[Home page] Books Code Blog Python Author Train Find ©M.Lutz