Analyzing the text file using Python


I have a huge log file which I want to parse using python. The file contains the data of working and non working audio/video/image file

The content of log.txt

filename = abc.mp4
played correctly

filname = cdf.wav

filename = rtg.mp3

Now from this log.txt how to find out failed filename I tried but seems like I not reaching at any point with that approach So I used following approach but so far I am not able the way to find out the filename

f = open('log.txt', 'r')
for i in f.realines():
    if "failed" in i:
        print "failed files: "

Save a reference to the filename temporarily, then add it to a list if it failed:

with open('log.txt') as f:
    result = []
    for line in f:
        line = line.strip()
        if not line:
        if '=' in line:
            name = line.split('= ')[1]
        if line == 'failed':

After the above, result will be a list with all the failed filenames.