【发布时间】:2014-12-17 10:29:58
【问题描述】:
我正在考虑一个函数,它能够通过将 DATEFORMAT 作为参数传递来在日志文件中找到时间戳,例如:
def find_some_dates(logfile, timestamp_format='%d/%b/%Y %H:%M:%S.%f'):
# find timestamps by timestamp_format
# pass it to datetime.strptime
# return unix timestamp
时间戳可以在一行内的任何位置。例如
[1] 17/Dec/2014 15:00:21.777 something happened
On 17/Dec/2014 15:00:21.777 something happened
17/Dec/2014 15:00:21.777 - something happened
我正在考虑某种映射,它采用 timestamp_format 并将其解析为正则表达式。有没有更好的方法?
【问题讨论】:
标签: python regex python-2.7