Python - How can I open a file and specify the offset in bytes?

前端 未结 8 1700
我在风中等你
我在风中等你 2020-12-17 14:37

I\'m writing a program that will parse an Apache log file periodically to log it\'s visitors, bandwidth usage, etc..

The problem is, I don\'t want to open the log an

8条回答
  •  难免孤独
    2020-12-17 15:28

    Easy but not recommended :):

    last_line_processed = get_last_line_processed()    
    with open('file.log') as log
        for record_number, record in enumerate(log):
            if record_number >= last_line_processed:
                parse_log(record)
    

提交回复
热议问题