Apr-11-2020, 01:30 PM
I used the contextlib library for my embedded console class but it works with anything that has a write method/function. It works really well with a context manager
from contextlib import redirect_stdout print('This goes to console') with redirect_stdout(open('junk.txt', 'w+')): print('This goes to a file') print('This is the last line to the file') print('This is back in the console')