Get last n lines of a file, similar to tail

前端 未结 30 2915
挽巷
挽巷 2020-11-22 03:46

I\'m writing a log file viewer for a web application and for that I want to paginate through the lines of the log file. The items in the file are line based with the newest

30条回答
  •  一个人的身影
    2020-11-22 04:16

    There is very useful module that can do this:

    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)
    

提交回复
热议问题