Using python 2.7 I am calling an external library function and I want to print all the logs/prints that this function generates to a file. I would like to update the file with the logs as they happen. I am using ipython notebook so if there is an easier way which is notebook specific I will be ok with that too.
Asked
Active
Viewed 59 times
1
-
1Possible duplicate: http://stackoverflow.com/questions/6796492/temporarily-redirect-stdout-stderr – Yoav Glazner Jan 06 '16 at 20:24
1 Answers
1
It's probably better to perform the redirection in your shell, not from within the python code.
From a typical Unix command line, you can use the tee
command:
python program.py | tee logfile

John Gordon
- 29,573
- 7
- 33
- 58