[Tutor] Trying to extract the last line of a text file
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Thu Oct 19 23:15:11 CEST 2006
> This works as well
>
> file('filename.txt').readlines()[-1]
>
> Some will say that this is no good because the file is still open.
> However I've been told that when the object is cleaned the file is
> closed so it should be fine.
It matters in an implementation like Jython, which depends on the
underlying Java runtime's garage collector to reap values. The issue
there is that we don't control the frequency of the garbage collector, so
we may exhaust all open files that the system provides before the
collector kicks in.
More information about the Tutor
mailing list