Listing subtypes

Diez B. Roggisch deets at nospam.web.de
Wed Nov 28 19:54:25 EST 2007


Ben Finney schrieb:
> Samuel <knipknap at gmail.com> writes:
> 
>> I remember seeing an easy way to list all subtypes of a specific type
>> but I haven't been able to find it anymore. What I am trying to do is
>> this: Given a class, get a list of all classes that derive from it.
>> Pretty much like __mro__ but downwards rather then upwards. Any ideas?
> 
> A class knows its parents; it doesn't know its children. (Or, in other
> words, children need to know who their parents are, but aren't
> required to notify their parents about anything.)

Not right. These special children are under a more demanding goverment.


class A(object):
     pass

class B(A):
     pass

print A.__subclasses__()


http://www.mail-archive.com/python-list@python.org/msg67979.html


Diez



More information about the Python-list mailing list