can i define a new method at runtime?

Raoul raoulsam at
Fri Jun 18 20:49:13 CEST 2004

I have a GUI application where I want to assign validation methods to

If my control myTextBox has a change() event for on change and I want
to make it verify the input is an integer I could do...

def myTextBox.change():

def verifyInteger(x):
   except ValueError :
      message(x," needs to be an integer")

but i have literally hundreds of these things to do....

I'd like to be able to say somethign like

myTextBox.change = lambda x : verifyInteger(x)

so when i initialize my form i'd like to run through a list that looks


but i can't seem to make this work.

I've tried to use exec("def foo = lambda x: do something....")

but that doesn't seem to work....

Got any ideas ???

More information about the Python-list mailing list