Thursday, 22 August 2013

Comparing a list with a a text document

Comparing a list with a a text document

So I generate a list within my code and now I want to check it against an
existing document to see what differences there are before making a new
document.
Here is my attempt:
diff = ""
if File2_Loc :
File2 = open( File2_Loc , 'r' )
for line in R_List :
if line in File2 :
pass
else :
diff += ( line.strip() + " not found in old file.\n" )
for line in File2 :
if line == "***** Differences founds : *****\n" :
print( "Compared!")
break
if line in R_List :
pass
else :
diff += ( line.strip() + " not found in new file.\n" )
else :
print( "No file inputted:" )
for line in R_List :
File1.write( line )
File1.write( "***** Differences founds : *****\n" )
if diff :
File1.write( diff )
else :
File1.write( "None.\n" )
The problem here is, every single line within R_List isn't found in File2,
even though 100% of them should be.
I've looked for a solution already, but I didn't see anything that
addressed my problem or worked for my problem.

No comments:

Post a Comment