first, second, etc line of text file

Jeff jeffober at
Wed Jul 25 22:00:28 CEST 2007

Files should be iterable on their own:

filehandle = open('/path/to/foo.txt')
for line in filehandle:
    # do something...

But you could also do a generic lines = filehandle.readlines(), which
returns a list of all lines in the file, but that's a bit memory

More information about the Python-list mailing list