I have 2 files as shown below
Branch Data:
open bus from 2311 to 3223 ck 1
open bus from 4321 to 3783 ck 1
.
.
.
I have around 100 branches like this
infile:
contingency 'b2_452'
QQQQQQQQ
open bus from 4321 to 3784 ck 1
end
.
.
.
I have around 200 contingencies like this
I am trying to get the output as shown below
excepted output files:
file1
contingency 'b2_452'
open bus from 2311 to 3223 ck 1
open bus from 4321 to 3784 ck 1
end
file2
contingency 'b2_452'
open bus from 4321 to 3783 ck 1
open bus from 4321 to 3784 ck 1
end
Here is my code
infile = open('Contingency.txt').read()
Brachdata = open('BranchData.txt', 'r')
i = 0
for branchline in Brachdata:
replace1 = branchline
i = i + 1
outputfile = open('file' + str(i) +'.txt', 'w')
for line in infile:
outputfile.write(line.replace('QQQQQQQQ', replace1))
outputfile.close()
I am new to python programming and not sure where I am going wrong. This code is creating two copies of my infile... not replacing QQQQQQQQ with the line.