File Compare with difflib.context_diff
JohnV
loftmaster at gmail.com
Thu Mar 19 01:25:28 EDT 2009
The below code does the trick with one small problem left to be solved
import shutil
import string
currentdata_file = r"C:\Users\Owner\Desktop\newdata.txt" # the current
download from the clock
lastdata_file = r"C:\Users\Owner\Desktop\mydata.txt" # the prior
download from the clock
output_file = r"C:\Users\Owner\Desktop\out.txt" # will hold delta
clock data
shutil.copy(currentdata_file, output_file)
f = open(lastdata_file, 'r')
read_data1 = f.read()
f.close()
f = open(currentdata_file, 'r')
read_data2 = f.read()
f.close()
replaceText = ''
file = open(output_file, 'w')
file.write(string.replace(read_data2, read_data1, replaceText))
file.close()
Contents of lastdata_file:
AU08JEDD011485H14472402210
AU08JEDD020163C14472502210
AU08JEDD005029C14480102210
AU08JEDD004923H14482002210
AU08AWOL000799H14483902210
Contents of currentdata_file:
AU08JEDD011485H14472402210
AU08JEDD020163C14472502210
AU08JEDD005029C14480102210
AU08JEDD004923H14482002210
AU08AWOL000799H14483902210
AU08AWOL000120H14495902210
AU08ARPU050241H14511702210
IF08DRTO008074H14520202210
IF08DRTO008089H14521102210
IF08DRTO008077H14553602210
IF08CHES000023H14594902210
Contents of output_file:
AU08AWOL000120H14495902210
AU08ARPU050241H14511702210
IF08DRTO008074H14520202210
IF08DRTO008089H14521102210
IF08DRTO008077H14553602210
IF08CHES000023H14594902210
output_file has a blank line at the top because of replaceText = ''
Is there something besides '' that I can use to not end up with a
blank line at the top of output_file, or what is the code to delete
the first line of that file?
Thanks
More information about the Python-list
mailing list