Reusing object methods?

Ivan Voras ivoras at _-_fer.hr
Fri Apr 29 13:45:54 EDT 2005


Can this be done: (this example doesn't work)

----
class A:

     def a_lengthy_method(self, params):
          # do some work depending only on data in self and params

class B:

     def __init__(self):
         self.a_lengthy_method = A.a_lengthy_method
         # I know that data in "self" of class B object is compatible
         # with that of class A object
----

I want to 'reuse' the same method from class A in class B, and without 
introducing a common ancestor for both of them - is this possible in an 
elegant, straightforward way?




More information about the Python-list mailing list