Create static method dynamically

Leif K-Brooks eurleif at ecritters.biz
Fri Mar 12 03:29:09 CET 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