I'm attempting to compare two CSV files (using import csv
) and I'm getting unexpected results.
I'm able to properly parse the CSV and I'm getting the expected output I need to properly compare the two files based on their appropriate column data -- email address from one file to email address in the other file.
What I don't understand, is that when I run this, the first print row
statement only shows the first entry in the CSV. If I move the print row
to above or below the inner for
loop, it properly iterates all lines.
Effectively it's only comparing the first line in csv1
into all lines in csv2
.
csv1
is a subset of potential values from csv2
.
import csv
csv1 = csv.reader(csv1)
csv2 = csv.reader(csv2)
for row in csv1:
# 'print row' works fine here.
for line in csv2:
print row #<----- First Print Row Statement
if row[2].lower() == line[2].lower():
print row
elif row[2].replace('olddomain.com','newdomain.com') == line[2]:
print row
# 'print row' works fine here too.