Adding methods to an object

Gabriele *darkbard* Farina darkbard at gmail.com
Thu Oct 13 15:06:20 CEST 2005


Hi, there is a way to add methods to an object dynamically? I need to
do something like this. I remember python allowed this ...

class A(object):
 def do(s, m):
  print m

 @staticmethod
 def init(obj):
  obj.do = A.do

class Test(object):
 pass

o = Test()
A.init(o)

o.do(10)

Now it gives me an error ... unbound method ...

tnx, gabriele




More information about the Python-list mailing list