The below is what I use, I got the code from the mail archives I think:
def main():
app = MyApp()
app.MainLoop()
if __name__ == '__main__':
class StderrFaker:
def write(self, message):
message = message.strip()
print message
sys.stderr = StderrFaker()
main()
···
-----Original Message-----
From: David Fraser [mailto:davidf@sjsoft.com]
Sent: Saturday, October 30, 2004 9:15 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] catching Python exceptions...Uwe C. Schroeder wrote:
> On Friday 29 October 2004 03:08 pm, Paul McNett wrote:
>
> >David Fraser wrote:
>
> >>Thanks Uwe, I know how to get tracebacks for a particular
exception.
> >>But in a wxPython app the tracebacks resulting from
events get printed
> >>out to the screen and the app continues.
> >>I want to catch *all* these tracebacks, not just catch errors in
> >>particular conditions...
> >>Is that just standard Python handling or is there a hook
in wxPython
> >>somewhere that does it?
>
> >Isn't it just sys.stderr? Try making a file object and setting
> >sys.stderr to that. Something like:
>
> >import sys
> >file = open("/tmp/err.txt", "w")
> >sys.stderr = file
>
>
>
> How about
>
> app=MainApp(redirect=1,filename='log.txt')
>
> where MainApp is the wx.App object of your application.
> That should redirect anything to log.txt - including all exceptions
>
> UweThanks, I'll try that too...
David
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org