from __future__ import with_statementclass OutWrapper(object): def __init__(self, realOutput, logFileName): self._realOutput = realOutput self._logFileName = logFileName def _log(self, text): with open(self._logFileName, 'a') as logFile: logFile.write(text) def write(self, text): self._log(text) self._realOutput.write(text)
然后,您必须在主Python文件(运行所有文件的文件)中对其进行初始化:
import sys sys.stdout = OutWrapper(sys.stdout, r'c:templog.txt')
对于记录异常,最简单的
MainLoop方法是将wx.App的方法包装在try..except中,然后提取异常信息,以某种方式保存它,然后通过重新引发异常
raise,例如:
try: app.MainLoop()except: exc_info = sys.exc_info() saveExcInfo(exc_info) # this method you have to write yourself raise
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)