linux

python read file from the bottom

hyem_2 2019. 10. 10. 14:54
    import os
     
    with open('logfile.txt', 'rb') as f:
    f.seek(-2, os.SEEK_END)
    while f.read(1) != b'\n':
    f.seek(-2, os.SEEK_CUR)
    print(f.readline().decode())

출처: https://www.quora.com/How-can-I-read-the-last-line-from-a-log-file-in-Python