>> file('filename.txt').readlines()[-1] > Not to hijack the thread, but what stops you from just putting a > file.close() after your example line? Which file should file.close() close? The problem is that we don't have a handle on the particular file we want to close off.