How can I properly validate TextCtrl input values?

7stud bbxx789_05ss at yahoo.com
Tue Apr 24 20:14:19 PDT 2007


> I guess then you'd have to use a Try..Except to catch the ValueError
> and deal with it?
> 

It's a simple idiom.  You can play around with this:

while(True):
    data = raw_input("Enter an int: ")
    try:    
        data = int(data)
        break  #if the conversion doesn't work, this doesn't execute
    except ValueError:
        pass    

Note: the conversion won't work for decimal numbers either--if there is
a character in the string that is not a digit, int() throws an exceptions, and
therefore a decimal point causes an exception.







More information about the wxpython-users mailing list