Python 파일 내용 역순 읽기

2021. 2. 10. 18:32서버 프로그래밍

이전에 사용하던 방법은 메모리에 한번에 올려서 처리하다보니 만족스럽지 않아서, file_read_backwards 라이브러리를 사용하도록 수정하였다.

from file_read_backwards import FileReadBackwards

with FileReadBackwards("/tmp/file", encoding="utf-8") as frb:

    # getting lines by lines starting from the last line up
    for l in frb:
        print(l)

file-read-backwards.readthedocs.io/en/latest/readme.html

 

file_read_backwards — file_read_backwards 2.0.0 documentation

Docs » file_read_backwards Edit on GitHub file_read_backwards Memory efficient way of reading files line-by-line from the end of file Features This package is for reading file backward line by line as unicode in a memory efficient manner for both Python 2

file-read-backwards.readthedocs.io