python csv reader selecting specific rows
Question: Suppose we have a text file as given below:

    
    
    sfgsdgfs >sfsf > "assfgs.jpg">sggw.sgw
    sgsdfghsg>sdgsgsgsg[]
    werw>"erqwer.jpg">egfwrewrw
    

How to extract the rows that contain .jpg? What is wrong with the following
code?

    
    
    import csv
    data = csv.reader (open ('outfile.txt', 'r'), delimiter = '"')
    for row in data:
        if '.jpg' in row:
            print (row)
    


Answer: `row` is a list of column data items, you should iterate over it too:

    
    
    import csv
    
    data = csv.reader(open('test.csv', 'r'), delimiter='"')
    for row in data:
        for item in row:
            if '.jpg' in item:
                print(item)
    

prints:

    
    
    assfgs.jpg
    erqwer.jpg
    

