我想在文件中搜索包含给定字符串但没有匹配大小写的所有行。如何使这段代码不区分大小写呢?
with open(logfile) as inf:
for line in inf:
if var in line:
print 'found',line
答案 0 :(得分:6)
with open(logfile) as fin:
for line in fin:
if var.lower() in line.lower(): # makes this case insensitive
print 'found', line.rstrip() # You will be printing double new lines
# without rstrip here