'How to add model.summary() to existing text file in Python Keras

I already have an existing text file with data. I wanted to append the model.summary() data to an already existing text file. I found here, that by using:

with open('modelsummary.txt', 'w') as f:
    with redirect_stdout(f):
        model.summary()

I can save the model.summary() to a text file.

I however what the model summary data appended to an already existing text file during run time without generating a new txt file.

Any help will be greatly appreciated.

Thanks!



Sources

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

Source: Stack Overflow

Solution Source