Python log-the-display problems
Question: I'm trying to log the terminal display produced by a script which contains a
Scipy optimization routine. I've tried three different ways, all with
disappointing results.

open() and cmd-prompt redirection (">") did not log the warnings nor the per-
iteration information I would like to keep track of; it only logged the
parameter solutions.

logging.basicConfig() produced a blank file.

If possible, I would like to be able to log the exact terminal display of a
script file. I've begun looking into using the logging module, but it seems
pretty complex for what I would think is a very basic task (I'm coming from a
Matlab background).

Environment:

. Python 2.7.3

. Operating Systems: Windows Vista and XP


Answer: Probably the stuff you're interested in is being sent to stderr rather than
stdout. Try redirecting both to a file. You can either do that in Python:

    
    
    import sys
    
    with open("log.txt", "w") as logfile:
        sys.stdout, sys.stderr = logfile, logfile
    
        # do your stuff here, e.g. import the module that you want to log
    

Or from the command line:

    
    
    python myscript.py > log.txt 2>&1
    

