The best way to filter a log by a dates range in python

前端 未结 5 1086
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 19:51

What\'s the best way to print log lines that match a datetime range. For example:

I would like to print only lines with dates from: 2012/09/30-00:00:10 to: 2012/09/

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-13 20:06

    Assuming you're reading the log line by line:

    import re
    for line in log:
        if re.match("2012/09/30-00:00:1[0-3]", line):
            print line
    

提交回复
热议问题