I have seen this question answered in reference to Bash, but can't find one for Python. Apologies if this is repeating something.
Is it possible to print to the terminal and an output file with one command? I'm familiar with using print >>
and sys.stdout = WritableObject
, but I'd like to avoid having to double print commands for each line I want logged.
I'm using Python 2.6, just in case such knowledge is necessary.
More importantly, I want this to run on a Windows-based system using IDLE's command line. So, in essence, I want the python script to report to IDLE's terminal and a given log file.
EDIT: For anyone who finds this and decides to go with the answer I chose, if you need help understanding context managers (like I did), I recommend Doug Hellman's Python Modules of the Week for clarification. This one details the context library. For help with decorators see this Stack Overflow question's answers.