How to print the console to a text file AFTER the

2019-05-09 13:07发布

I have a program that outputs many calculations and results to the console through the print statement. I want to write some code to export (or save) all the contents of the console to a simple text file.

I searched StackOverflow and other sites but I found some methods to redirect the print statement to print to a file directly, but I want the program to work normally, to display outputs to the console, then to save its contents AFTER all operations of the program done.

I am using PyCharm with Python2.7 if it matters

7条回答
在下西门庆
2楼-- · 2019-05-09 13:49

After I know understood your question I think you search the tee command

python your_program | tee output.txt

This will show you the output both, in the console and in output.txt

PS: Since you did not answer to my comment which OS you use I assumed that you use either Linux or MACOS. Should work on both. I don't know how to do this on windows...

查看更多
登录 后发表回答