I'm trying to compare two excel documents to each other, they are made up of around 6000 rows and 4 columns, the first column is a domain name, the other three are comments, one of the documents has updated comments in some of the columns and eventually I would like this script to function like a batch update of new comments replacing the old outdated ones.
The code I have written so far opens the documents and adds them to two separate lists:
import csv
newlist = csv.reader(open('newcomments.csv','rU'), dialect='excel')
export = csv.reader(open('oldcomments.csv', 'rU'), dialect='excel')
for row in newlist:
olddomain=[]
domain = row[0:]
olddomain.append(domain)
for item in olddomain:
print item
for row in export:
newdomain=[]
domain= row[0:]
newdomain.append(domain)
for item in newdomain:
print item
the output from the lists looks like(the second column is normally blank):
['example.com', '', 'excomment', 'Parked Page']
When trying to compare the lists i have tried something like:
if item in olddomain != item in newdomain:
print "no match"
else:
print "match"
but that doesn't appear to work,for example, the first row in the two files contain the exact same data, but the code returns "no match", the second row in both files also contains the same data, but the code returns "match"
Is the problem with the way I am saving the rows to the list, or is there something else I'm missing? I'm going to assume there is a better way of doing this but I'm using it as an excuse to learn more python!
Thanks for your time.