Note raise! Very useful.

#!/usr/bin/env python2


def getlineword(filelist, lineno):
    """
    Line number one is the first line
    Returns first word on the line.
    """
    try:
            return filelist[lineno-1].split()[0]
    except:
            raise

if __name__ == '__main__':
    """
    Does a head
    """
    file = open('../file_list')
    filelist = file.readlines()
    for i in range(1,11):
            print 'Line no: %s\tEntry: %s' % (i,   getlineword(filelist, i))
    file.close()
Feedback

Powered by Vanilla PHP feedback form