Why is this writing part of the text to a new line? (Python)
- by whatsherface
I'm adding some new bits to one of the lines in a text file and then writing it along with the rest of the lines in the file to a new file. Referring to the if statement, I that to be all on the same line:
x = 13.55553e9
y = 14.55553e9
z = 15.55553e9
infname = 'afilename'
outfname = 'anotherone'
oldfile = open(infname)
lnum=1
for line in oldfile:
if (lnum==18):
line = "{0:.2e}".format(x)+' '+line+' '+"{0:.2e}".format(y)+' '+ {0:.2e}".format(z)
newfile = open(outfname,'w')
newfile.write(line)
lnum=lnum+1
oldfile.close()
newfile.close()
but y and z are being written on the line below the rest of it. What am I missing here?