Export Coordinates of Motion of a continuous animation

Hi there. I need to obtain the XYZ coordinates for my objects in the animation into a text file and understand that it is possible to do so through Python. However, I can’t seem to obtain the proper code even through googling. I’ve found one but that creates only a single file for that single frame but is it possible to have a code that does the entire animation for the object in mind?

The code that I have searched through the forums and provided by CoDEmanX is as follows.
I’ve edited it too so that it only shows the parameters that I need.

import bpy

with open(r"C: mp\output.txt", “w”) as file:
for ob in bpy.context.scene.objects:
if “Torus” in ob.name:
mat = ob.matrix_world
loc = mat.translation.xzy[:]

        print(ob.name, "	".join(map(str, loc)))
        
        file.write("	".join(map(str, (ob.name,) + loc)))
        file.write("

")

I’m a newbie at this and am struggling to understand some of the terms applied. However I do know that I am probably in need of a variable for the frames so that the tabulation can move along? Would really appreciate any assistance!!