finding abc's
lars van gemerden
lars at rational-it.com
Fri Jan 25 12:40:49 EST 2013
Hi all,
i was writing a function to determine the common base class of a number classes:
def common_base(classes):
if not len(classes):
return None
common = set(classes.pop().mro())
for cls in classes:
common.intersection_update(cls.mro())
while len(common) > 1:
cls1 = common.pop()
cls2 = common.pop()
if issubclass(cls1, cls2):
common.add(cls1)
elif issubclass(cls2, cls1):
common.add(cls2)
return common.pop()
and ran common_base(int, float), hoping to get numbers.Number.
this did not work because abstract base classes are not always in the mro() of classes.
My question is: is there a way to obtain the abc's of a class or otherwise a way to make the function above take abc's into account (maybe via a predefined function)?
Cheers, Lars
More information about the Python-list
mailing list