Why is this writing part of the text to a new line? (Python)

Posted by whatsherface on Stack Overflow See other posts from Stack Overflow or by whatsherface
Published on 2012-09-03T03:27:25Z Indexed on 2012/09/03 3:38 UTC
Read the original article Hit count: 77

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about python

Related posts about io