wxpython 中的输出重定向
试图了解如何将程序输出重定向到文件...
代码:
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
Trying to understand, how to redirect program output to a file...
Code:
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()
OUTPUT:
File "./output.py", line 38
app = App(redirect=True, "output.txt")
SyntaxError: non-keyword arg after keyword arg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用第一个关键字参数时,所有其余参数也必须是关键字参数。
app = App(redirect=True, filename="output.txt")
When you use first keyword argument, all the rest arguments have to be keyword arguments also.
app = App(redirect=True, filename="output.txt")