Reading from CSVs in Python repeatedly?

前端 未结 2 488
渐次进展
渐次进展 2020-11-27 21:29

I\'m trying to check the value of extracted data against a csv I already have. It will only loop through the rows of the CSV once, I can only check one value of feed.items()

2条回答
  •  执念已碎
    2020-11-27 22:14

    You can "reset" the CSV iterator by resetting the read position of the file object.

    data = open("googlel.csv", "rb")
    orig = csv.reader(data, delimiter = ';')
    goodrows = []
    for feed in gotfeeds:    
       for link,comments in feed.items():
           data.seek(0)
           for row in orig:
               print link
               if link in row[1]:
                   row.append(comments)
                   goodrows.append(row)
    

提交回复
热议问题