试图了解如何将程序输出重定向到文件......
代码:
import sys
import os
import wx
class Frame(wx.Frame):
def __init__(self, parent, id, title):
print "Frame __init__"
wx.Frame.__init__(self, parent, id, title)
class App(wx.App):
def __init__(self, redirect=True, filename=None):
print "App __init__"
wx.App.__init__(self, redirect, filename)
def OnInit(self):
print "OnInit"
self.frame = Frame(parent=None, id=-1, title='Startup')
self.frame.Show()
self.SetTopWindow(self.frame)
print >> sys.stderr, "A pretend error message"
return True
def OnExit(self):
print "OnExit"
def main():
app = App(redirect=True, "output.txt")
print "before MainLoop"
app.MainLoop()
print "after MainLoop"
if __name__ == '__main__':
main()
输出:
File "./output.py", line 38
app = App(redirect=True, "output.txt")
SyntaxError: non-keyword arg after keyword arg
答案 0 :(得分:1)
当您使用第一个关键字参数时,所有其余参数也必须是关键字参数。
app = App(redirect=True, filename="output.txt")