【发布时间】:2015-09-21 09:40:52
【问题描述】:
我的查询是我想从文本文件中搜索单词并打印包含这些单词的行。所有单词都作为用户输入给出。 不知何故,我到达了这一点,它的输出什么都没有。
def sip(x):
print("====Welcome to SIP log Debugger ==== ")
file= input("Please Enter log File path: ")
search = input("Enter the Errors you want to search for(seperated with commas): ")
search = [word.strip() for word in search.lower().split(",")]
with open(file,'r') as f:
lines = f.readlines()
line = f.readline()
for word in line.lower().split():
if word in line:
print(line),
if word == None:
print('')
【问题讨论】:
-
word永远不会是None:它是一个字符串。 -
在检查
word in line之前是否尝试过打印每个单词(和行)? -
def http(y): for line in file2: if re.search('401',line) or re.search('HTTP/1.1',line): print(line), if行 == 无:打印('')
标签: python file python-3.x