I am new to python. I am trying to use a file with new data (newprops) to replace the old data on a second file. Both files are over 3MB.
File with new data looks like this:
PROD 850 30003 0.096043
PROD 851 30003 0.096043
PROD 853 30003 0.096043
PROD 852 30003 0.096043
....
Original file with old data is something like:
CROD 850 123456 123457 123458 123459
PROD 850 30003 0.08
CROD 851 123456 123457 123458 123459
PROD 851 30003 0.07
CROD 852 123456 123457 123458 123459
PROD 852 30003 0.095
CROD 853 123456 123457 123458 123459
PROD 853 30003 0.095
....
Output should be:
CROD 850 123456 123457 123458 123459
PROD 850 30003 0.096043
CROD 851 123456 123457 123458 123459
PROD 851 30003 0.096043
CROD 852 123456 123457 123458 123459
PROD 852 30003 0.096043
CROD 853 123456 123457 123458 123459
PROD 853 30003 0.096043
Here's what I have so far:
import fileinput
def prop_update(newprops,bdffile):
fnewprops=open(newprops,'r')
fbdf=open(bdffile,'r+')
newpropsline=fnewprops.readline()
fbdfline=fbdf.readline()
while len(newpropsline)>0:
fbdf.seek(0)
propname=newpropsline.split()[1]
propID=newpropsline.split()[2]
while len(fbdfline)>0:
if propID and propname in fbdfline:
bdffile.write(newpropsline) #i'm stuck here... I want to delete the old line and use updated value
else:
fbdfline=fbdfline.readline()
newpropsline=fnewprops.readline()
fnewprops.close()
Please help!
newpropsand which block of data isbdffileto better assist you.