cleaner way to write this try/except statement?
John Salerno
johnjsal at NOSPAMgmail.com
Wed Aug 2 10:23:48 EDT 2006
John Salerno wrote:
> The code to look at is the try statement in the NumbersValidator class,
> just a few lines down. Is this a clean way to write it? i.e. is it okay
> to have all those return statements? Is this a good use of try? Etc.
Ok, I came up with this. It looks much nicer, I think, though I'm still
unsure if it's good to have three separate return statements:
def Validate(self, parent):
text = self.GetWindow().GetValue()
try:
if int(text) != 0:
return True
else:
self.error_message()
return False
except ValueError:
self.error_message()
return False
But instead of a pop-up box for the error, I've decided to take Peter's
advice and change the status text instead (plus color the input box).
But here's an ultra OO newbie question: how do I refer to my frame's
children from within the validator class? :)
More information about the Python-list
mailing list