Single test for a class and all its subclasses?
Anthra Norell
anthra.norell at tiscalinet.ch
Wed Jun 15 04:04:21 EDT 2005
class C: ...
class C2 (C): ...
# What I want to do:
if x.__class__ in (C, C2):
do_something_with (x)
# Requires an exhaustive genealogy, which normally is impractical and often impossible
# Another approach
class_tree = inspect.getclasstree ((x.__class__,))
if classtree_contains (class_tree, C):
do_something_with (x)
# An awful lot of activity for a simple task
I'd expect a attribute name like __class__, but haven't found one in the doc and my doc-search time-out setting for simple things like this is about one hour.
Frederic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050615/7210ae66/attachment.html>
More information about the Python-list
mailing list