I am parsing log files in size of 1 to 10GB using python3.2, need to search for line with specific regex (some kind of timestamp), and I want to find the last occurance.
I have tried to use:
for line in reversed(list(open("filename")))
which resulted in very bad performance (in the good cases) and MemoryError in the bad cases.
In thread: Read a file in reverse order using python i did not find any good answer.
I have found the following solution: python head, tail and backward read by lines of a text file very promising, however it does not work for python3.2 for error:
NameError: name 'file' is not defined
I had later tried to replace File(file)
with File(TextIOWrapper)
as this is the object builtin function open()
returns, however that had resulted in several more errors (i can elaborate if someone suggest this is the right way:))