Find the closest relative
jm.suresh@no.spam.gmail.com
jm.suresh at gmail.com
Fri May 25 02:31:50 EDT 2007
Hi I have three objects, all of them are instances of classes derived
from a base class. Now, given one of the instance, I want to find the
closest relative of the other two. How can I do this?
This is how I implemented; I guess there must be elegant way to do
this...
def find_closest_relative(a,b,c):
c1 = b.__class__
c2 = b.__class__
while True:
if isinstance(a, c1):
return b
if isinstance(a, c2):
return c
c1 = c1.__base__
c2 = c1.__base__
-
Suresh
More information about the Python-list
mailing list