网上查了下pythonw.exe是什么东西,原来它就是无窗口的python可执行程序
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.
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.
以下是摘录自百度问题的答案:
严格来说,它们之间的不同就只有一个:视窗运行它们的时候调用不同的执行档案。 视窗用 <a target=_blank href="http://lib.csdn.net/base/11" target="_blank" style="color: rgb(51, 102, 153); text-decoration: none;">python</a>.exe 运行 .py ,用 pythonw.exe 运行 .pyw 。 这纯粹是因为安装视窗版 Python 时,扩展名 .py 自动被登记为用 python.exe 运行的文件, 而 .pyw 则被登记为用 pythonw.exe 运行。 .py 和 .pyw 之间的“其它差别”全都是 python.exe 和 pythonw.exe 之间的差别。 跟 python.exe 比较起来,pythonw.exe 有以下的不同: 1)执行时不会弹出控制台窗口(也叫 DOS 窗口) 2)所有向原有的 stdout 和 stderr 的输出都无效 3)所有从原有的 stdin 的读取都只会得到 EOF .pyw 格式是被设计来运行开发完成的纯图形界面程序的。 纯图形界面程序的用户不需要看到控制台窗口。 值得一提的是,开发纯图形界面程序的时候,你可以暂时把 .pyw 改成 .py , 以便运行时能调出控制台窗口,看到所有错误信息,方便除虫。 注:唯独视窗版 Python 有 .pyw 格式。
转自:<a target=_blank target="_blank" href="http://zhidao.baidu.com/link?url=N1x_UNV1ErPhyljcLr48roMvAxO2HOCvuJL9eZPIGQ2bLjYFDTjZbEnwhhwKOvWpRhzT-TQCN7vyjK-QmLyPW_" style="color: rgb(51, 102, 153); text-decoration: none;">http://zhidao.baidu.com/link?url=N1x_UNV1ErPhyljcLr48roMvAxO2HOCvuJL9eZPIGQ2bLjYFDTjZbEnwhhwKOvWpRhzT-TQCN7vyjK-QmLyPW_</a>