Create static method dynamically

Leif K-Brooks eurleif at ecritters.biz
Thu Mar 11 21:29:09 EST 2004


Salvatore wrote:
> class myClass:
>     def addmethod(name,method):
>         maClasse.__dict__[name] = method
>     addmethod = staticmethod(addmethod)
> 
> def hello():
>     print "hello"
> 
> myClasse.addmethod('hello',hello)
<snip>
> I would like to make this call:
> myClass.hello()

Change line 3 to:
         myClass.__dict__[name] = staticmethod(method)



More information about the Python-list mailing list