Cmag
Cmag

Reputation: 15760

Output redirection in wxpython

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

Upvotes: 0

Views: 673

Answers (1)

Fenikso
Fenikso

Reputation: 9451

When you use first keyword argument, all the rest arguments have to be keyword arguments also.

app = App(redirect=True, filename="output.txt")

Upvotes: 1

Related Questions