def search_file(file_path, word): with open(file_path, 'r') as file: for line in reversed(file.readlines()): if word in line: return line speed = search_file('E:/Projects/python/ffmpeg_work_folder/testoutprogress.txt', 'speed=') frame = search_file('E:/Projects/python/ffmpeg_work_folder/testoutprogress.txt', 'frame=') print(speed) print(frame)