【发布时间】:2015-11-02 10:28:08
【问题描述】:
如何过滤掉两个时间戳之间的行并仅在 Python 中打印这些行?
示例:我想过滤 08:00:00 am 到 05:00:00 pm 我尝试了类似的方法,但它不起作用。
def ipaddr(w):
print("====Welcome to HTTP log Debugger ==== ")
file= input("Please Enter log File path: ")
start_time = input("start Time: ")
End_time = input("End Time : ")
with open(file,'r') as f:
lines = f.read().splitlines()
for L in lines:
if L.startswith(start_time):
p= 1
elif L.startswith(End_time):
p=0
break
if p: print(L)
【问题讨论】:
-
提供样本输入数据。请阅读this
-
并且比“它不起作用”更具体。
标签: python python-3.x