0

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)
1
  • I think the delimiter should be >. Or you don't have to use csv.@guava Commented Jul 19, 2013 at 9:21

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much, i will accept your answer after 8 minutes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.