print msg into file
Posted: 04 Sep 2019, 07:14
I'm wondering if the msg can be printed into a log file?
It's not hard to modify the code, and I think this is necessary.
It's not hard to modify the code, and I think this is necessary.
Community forum for the Tensor Network Python (TeNPy) Package
https://tenpy.johannes-hauschild.de/
> at the and of any command to redirect all standard output (which usually get's printed on your terminal otherwise.&>, both the standarad output and standard error get redirected, such that you also get tracebacks and error messages.Code: Select all
python my_script.py > file_where_stdout_appears.txt # here, error messages still get printed to your terminal
python my_script.py &> file_for stdout_and_stderr.txt # here, both output and error messages get redirected to the file
python my_script.py > file_for_stdout.txt 2> file_for_stderr.txt # redirect error message to different file
Python: Select all
with open('help.txt', 'w') as f:
with redirect_stdout(f):
help(pow)
Python: Select all
from contextlib import redirect_stdout
def my_function():
print("here, I could call tenpy models...")
print("this is still usual output")
with open('myoutput.txt', 'w') as f:
with redirect_stdout(f):
my_function()
print("and this is again usual output")
redirect_stderr, it does not seem to redirect any python error messages...)Code: Select all
python3 -u abc.py > log.txt
Python: Select all
import time
for i in range(100):
print(i)
time.sleep(1)
Python: Select all
flush=True