finding last match in a file
David Mertz, Ph.D.
mertz at gnosis.cx
Thu Sep 19 17:10:44 EDT 2002
|..find the last line which matches a certain experssion. ...Is there
|some way to read through the file backwards and simply find first match
|starting from the end of the file.
I provide one solution in my _Text Processing in Python_ book
(forthcoming as dead trees, available now as ASCII). The book itself is
at:
http://gnosis.cx/TPiP/
In chapter 2, I have a section titled:
PROBLEM: Reading a file backwards by record, line, or paragraph
I'm sure improvements are possible (it's meant to point to the approach,
not necessarily be the final code). But what I do should be pretty
efficient (as I mention, for 2.2+, I'd rather use 'yield').
Yours, David...
--
---[ to our friends at TLAs (spread the word) ]--------------------------
Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego
White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad
---[ Postmodern Enterprises <mertz at gnosis.cx> ]--------------------------
More information about the Python-list
mailing list