I need a little bit of help here with comparing data sets.
file1 = open("filename1.txt", "r") file2 = open("filename2.txt", "r") fileone = file1.readlines() filetwo = file2.readlines() file1 = close() file2 = close() exfile = open("results.txt", "w") for line1 in fileone: s1, v1, p1 = line[:-1].split(":") for line2 in filetwo: s2, v2, p2 = line[:-1].split(":") if st1 != st2 and vt1 != vt2: print("Please make sure you did not misspell column1 or change the number of votes and try again") exfile.close()
So its a rough product here. I'm missing a line of code towards the end. Anyways the two files I'm opening will be divided into 3 columns with a colon. So essentially it'll look something like:
Pretty much the last column changes while the first two remains the same, generally speaking.
When I read 1 file, what I did was use a for loop to read each line similar to how I did it above. Now the issue is I have two files and I need to split each line of the file up similar to how I did it with 1 file.
The goal of the program is to read two files, output a new file with where column 1 and column 2 remains the same, but column 3 is replaced by the data from filename2.txt. Because I was hoping to use a while statement like:
while s1 == s2 and v1 == v2: exfile.write(s1,":",v1,":",p2)