Editing a single line in a file using python. Missing last part of new file

I am trying to edit a single line in a povray file using python.

The file starts as follows:

camera {
 angle 38
 location <500,0,0>
 right x*image_width/image_height
 look_at <0,0,0>
 rotate <0,0,0>
}

and I want to edit the variables described in the file so that it looks like this:

camera {
 angle 38
 location <1000,1000,1000>
 right x*image_width/image_height
 look_at <10,10,10>
 rotate <30,30,30>
}

To do this, I use the following method:

def updateCamera(self, filename):
        tmp = "povrayContent/temp.pov"
        lines = open(filename, 'r')
        out = open(tmp , 'w')
        for line in lines:
            if " angle" in line:
                out.write(" angle "+str(int(self.camAngle))+"\n")
            elif " location" in line:
                out.write(" location <"+str(int(self.camera[0]))+","+str(int(self.camera[1]))+","+str(int(self.camera[2]))+">\n")
            elif " look_at" in line:
                out.write(" look_at <"+str(int(self.camera[3]))+","+str(int(self.camera[4]))+","+str(int(self.camera[5]))+">\n")
            elif "rotate" in line:
                out.write(" rotate <"+str(int(self.camera[6]))+","+str(int(self.camera[7]))+","+str(int(self.camera[8]))+">\n")
            else:
                out.write(line)
        shutil.copy(tmp, filename)

EDIT: , , . , , . , 40 . . , , , 20 . - , , - python, ?

+3
1

, , .

+7

All Articles