pythonw.exe doesn't have a console so I can't see the output of print. But my program is OKAY in python.exe, failed in pythonw.exe. I just want to see the logs from python interpreter and the log printed by my "print" statement, is it doable?
+1
A:
You can redirect the output of print to any stream. For example
logfile = open("logfile.txt", "w")
print >>logfile, "This is a log test"
Although most of the time it would be more appropriate to use python's built-in logging facilities from the logging
module.
FloDo
2010-09-09 08:20:58
+1
A:
If you run your program from a Python IDE such as Stani's Python Editor, Komodo or similar, you can see your output on the output window.
As an alternative you can send your prints to a log file. The standard way is to use the logging module. Alternatively you can use prints directed to a file with '>>'
Also it can be done directly from the command line. As an example, In the windows shell I often use:
doit.exe >> milog.txt
joaquin
2010-09-09 08:21:14
+2
A:
You can globally redirect stdout by assigning to sys.stdout:
import sys
sys.stdout = open("mylog.txt", "w")
Then the rest of your program's stdout, including print statements, will go to mylog.txt.
Ned Batchelder
2010-09-09 10:44:51