__subclasses__
James Rowe
jimrowe at optilink.com
Thu Jun 13 13:57:47 EDT 2002
A search for __subclasses__ on the www.python.org
documentation search pages turns up empty. I can
find not mention of it in my Python books or even
in the "What's new in Python 2.2" document. But:
class Foo(object):
def __init__(self):
object.__init__(self)
class Bar(Foo):
pass
dir(Foo) # returns:
['__class__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__',
'__new__', '__reduce__', '__repr__', '__setattr__',
'__str__', '__weakref__']
But there is a __subclasses__ method:
Foo.__subclasses__() # returns:
[<class '__main__.Bar'>]
So I suppose the question is: Why is __subclasses__ not documented
or listed? Can we safely use __subclasses__ and not worry about
it "going away" in the future?
More information about the Python-list
mailing list