can i define a new method at runtime?

Jeff Epler jepler at
Mon Jun 21 13:56:13 CEST 2004

Something like the untested code below will work, without the need to
"exec" anything.

def verifyInteger(x): ...
def verifyFloat(x): ...
verifiers = {"ControlName1": verifyInteger, "ControlName2": verifyFloat, ...}

class MyTextBox(TextBox):
    def __init__(self, controlname, ...):
        self.verifyfunc = verifiers[self.controlname]
        TextBox.__init__(self, ...) 
    def change(self):

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list