cleaner way to write this try/except statement?

infidel saint.infidel at gmail.com
Tue Aug 1 17:55:57 EDT 2006


Here's how I would do it:

    def Validate(self, parent):
        try:
            text_ctrl = self.GetWindow()
            text = text_ctrl.GetValue()
            if not text: raise ValueError
            if int(text) <= 0: raise ValueError
            return True
        except ValueError, error:
            wx.MessageBox('Enter a valid time.', 'Invalid time
entered', wx.OK | wx.ICON_ERROR)
            return False




More information about the Python-list mailing list