I
I
Igor Nikolaev2015-06-10 18:12:33
Python
Igor Nikolaev, 2015-06-10 18:12:33

How to read only the last 30 lines from a file?

The question is concise, we need a similar answer :)
The task is to get statistics from 100500 log files, 1-30 Mb in size.
To speed up the process, I consider it advisable to read only the last 30 lines in the file, which contain all the information I need.
How to do it in Python?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leo, 2015-06-10
@nightvich

import os
r = os.system("tail -n 30 /path/error.log")
print(r)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question