'Save files of a modeling program in different files .txt

hello I am New to Python, I have worked with a library design by a professor in my university I need help to save the results in different files .txt and in different folders

The model consists of a mesh of 2500 cells with coordinates x, y, z. I want in every step of the iteration to get a file .txt that has cell index, the coordinates of each cell, and the different attributes of this cell, I wrote the code below but I obtained the last cell index and the position 0.0.0... in only one file txt, and I don't know how to save it in a folder...

if os.path.exists('Model'):
    import shutil
    shutil.rmtree('Model')
os.mkdir('Model')

def save_m1(path, fluid_index):
assert isinstance(path, str)
with open(path, 'w') as file:
    for cell in model.cells: 
        x, y, z = cell.pos
        file.write(f'{cell.pos} {model.cell_number} {cell.get_fluid(fluid_index).mass}\n')
        if step % 100 == 0:
            model.print_cells("Model" % step)
dt = 10.0
for step in range(10):

model.iterate(dt=dt)
thermal.iterate(dt=dt)
thermal.exchange_heat(model, dt=dt, fid=0, na_g = na_g, fa_T = ID_T, fa_c = ID_K)
thermal.exchange_heat(model, dt=dt, fid=1, na_g = na_g, fa_T = ID_T, fa_c = ID_K)
thermal.exchange_heat(model, dt=dt, fid=2, na_g = na_g, fa_T = ID_T, fa_c = ID_K)


    print(f'step = {step}, m1_produced = {get_mass1_produced(1) - InitialMass1}') #  kg

save_m1('xxx.txt', 1)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source