Reading from CSVs in Python repeatedly?

前端 未结 2 486
渐次进展
渐次进展 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:07

    Making orig a list avoids the need to reset/reparse the csv:

    orig = list(csv.reader(open("googlel.csv", "rb"), delimiter = ';'))
    
    0 讨论(0)
  • 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)
    
    0 讨论(0)
提交回复
热议问题