1

I want to search a file for all lines containing a given string without matching case. How can I make this code case-insensitive?

with open(logfile) as inf:
    for line in inf:
        if var in line:
            print 'found',line
4

1 回答 1

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
于 2012-08-10T13:09:07.140 回答