There are standard methods to print the putput of a program to an output file like this. Is there a way to use the print
function for different outputs? I understand that the loop
with open('out.txt', 'w') as f:
with redirect_stdout(f):
print('data')
only prints to the out.txt file once we enter the with
-"loop". How can I use the same snippet to do instead
for i in range(isteps):
# Do something with the program
with open('out.txt', 'w') as f:
with redirect_stdout(f):
print('data') # Writes in out.txt
print1('Status') # Writes on the screen
Note that the for
loop outside the with
's is part of a bigger program that makes some computation. I would like to print the data in the file but at the same time monitor the status of the program (displayed on the screen).