Search code examples
pythonpython-2.7spyderpythonxy

How to (using console) put results in a txt. file or get complete results from a code that has already runned


i'm currently solving optimization problems with python. One problem takes about 5hrs to solve which result will appear (sadly) in console but not completely since it's a very big list. I'm wondering right now if there is anyway to get the solution of the list completely while i'm waiting for the results (i've been waiting for 4hrs. now).

If there is a way i can get the complete result in the console after the code has runned, let me know. If there is a way via console to put the results in a .txt file or any type of readable file afterwards please let me know.

If there is no solution to this problem, let me know.

Thanks alot.


Solution

  • Suppose your python file is myfile.py, in order to redirect what is printed in this file run your file as:

    python myfile.py > myfile.txt
    

    Your printed list will be printed in myfile.txt.