Found a message on the web that says I need to use setattr to add the method to the class at run time. But how do I do that?
Regards, On Jun 22, 12:02 pm, John Henry <[EMAIL PROTECTED]> wrote: > Hi list, > > I have a need to create class methods on the fly. For example, if I > do: > > class Dummy: > def __init__(self): > exec '''def method_dynamic(self):\n\treturn > self.method_static("it's me")''' > return > > def method_static(self, text): > print text > return > > I like that to be the same as: > > class Dummy: > def __init__(self): > return > > def method_dynamic(self): > return self.method_static("it's me") > > def method_static(self, text): > print text > return > > so that I can do: > > dum=Dummy.method_dynamic() > > and see "it's me" printed. > > Can that be done? > > Thanks, -- http://mail.python.org/mailman/listinfo/python-list