Dynamic class methods misunderstanding

Diez B. Roggisch deetsNOSPAM at web.de
Fri Jan 28 10:57:37 EST 2005


> 
> Why doesn't m get the implicit self parameter in the self.method()
> call? How would I make it a proper member of the class, so that a
> self.method() call would work with the above "m" function?

Use new.instancemethod:

import new

class Test:
    def __init__(self, method):
        self.m = new.instancemethod(method, self, Test)
        
def m(self):
    print self

Test(m).m()


-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list