我想在文件中搜索包含给定字符串的所有行而不匹配大小写.如何使此代码不区分大小写?
with open(logfile) as inf:
for line in inf:
if var in line:
print 'found',line
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
59 次 |
| 最近记录: |