1

大文字と小文字を一致させずに、指定された文字列を含むすべての行をファイルで検索したいと思います。このコードで大文字と小文字を区別しないようにするにはどうすればよいですか?

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 に答える