We have two log files in which one is generated from a process. We compare one file(golden file) to another file to check if file correct or not. It should have same value. We generally use diff utility to compare two files. I have got enhancement to add machine information into process generated File. So I want to compare upto previous line and ignore new changes. Could Anyone provide me any utility which I can use in python.
Golden File
CMD gen -vdd 0.99 -vss 0 -sinps 0.02 -slew 0.1 -temp -40 -rise -data
CMD gen -vdd 0.99 -vss 0 -sinps 0.06 -slew 0.1 -temp -40 -rise -clock
CMD gen -vdd 0.99 -vss 0 -sinps 0.02 -slew 0.1 -temp -40 -fall -data
CMD gen -vdd 0.99 -vss 0 -sinps 0.02 -slew 0.1 -temp -40 -fall -data
CMD gen -vdd 0.99 -vss 0 -sinps 0.06 -slew 0.1 -temp -40 -rise -clock
CMD gen -vdd 0.99 -vss 0 -sinps 0.02 -slew 0.1 -temp -40 -rise -data
Temp1 Temp2 Temp3 Temp4 Temp5 Temp6
-31.00 -19.00 -3.00 -8.00 43.00 61.00
Process File
CMD gen -vdd 0.99 -vss 0 -sinps 0.02 -slew 0.1 -temp -40 -rise -data
CMD gen -vdd 0.99 -vss 0 -sinps 0.06 -slew 0.1 -temp -40 -rise -clock
CMD gen -vdd 0.99 -vss 0 -sinps 0.02 -slew 0.1 -temp -40 -fall -data
CMD gen -vdd 0.99 -vss 0 -sinps 0.02 -slew 0.1 -temp -40 -fall -data
CMD gen -vdd 0.99 -vss 0 -sinps 0.06 -slew 0.1 -temp -40 -rise -clock
CMD gen -vdd 0.99 -vss 0 -sinps 0.02 -slew 0.1 -temp -40 -rise -data
Temp1 Temp2 Temp3 Temp4 Temp5 Temp6
-31.00 -19.00 -3.00 -8.00 43.00 61.00
Adding machine name( ignore machine name)
I have write code in following.Can we better way for improve code
data = None
with open("Golden_File",'r+') as f:
data = f.readlines()
del data[-1]
data_1 = None
with open("cp.log",'r+') as f:
data_1 = f.readlines()
del data_1[-1]
print cmp(data, data_1)
[Question]: Does cmp function works fine in list also. I have used first time and not sure how internally works.
Process File
. Correct? If correct then why are you deleting the last line in data. Wouldn't that delete the last line from what you have read from theGolden File
? \$\endgroup\$cmp
does indeed work for lists - see docs.python.org/2/tutorial/… and docs.python.org/2/library/functions.html#cmp. But you could just as easily typeprint data == data_1
\$\endgroup\$