[Tutor] Trying to extract the last line of a text file

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Oct 19 23:10:41 CEST 2006


>> 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.


More information about the Tutor mailing list