word = u'какое-то слово'
with open('файл.log', encoding='utf-8') as file:
for line in file:
if word in line:
print (file.read(10))
word = 'python'
last_line = ''
with open('файл.log', encoding='utf-8') as file:
while True:
file_line = file.readline()
if not file_line:
break
if word in file_line:
last_line = file_line
print(last_line)
from file_read_backwards import FileReadBackwards
word = 'python'
with FileReadBackwards('log.log', encoding="utf-8") as frb:
while True:
line = frb.readline()
if not line:
break
if word in line:
print(line)
break
functools.reduce(lambda a, b: a and b, filter(lambda line: word in line, open('файл.log')))