Joe Mason <joe@notcharles .ca> wrote in message news:<slrnc6cr9 n.dit.joe@gate. notcharles.ca>. ..[color=blue]
> Cool. How come this isn't in either the Language Reference or Library
> Reference? I just skimmed through those looking for special
> class-related methods the other day, when I first started looking at
> prototypes, and didn't notice __subclasses__, and now I can't find it in
> the index.[/color]
Google this newsgroup for __subclasses__. For some reason the
developers choose not to document it, but it is there and it seems to be
working. Just as curiosity, __subclasses__ is a meta-method, i.e. it
is a method of the metaclass "type" and not a class method of "object".
For this reason "dir" does not show it
[color=blue][color=green][color=darkred]
>>> class C(object): pass[/color][/color][/color]
....[color=blue][color=green][color=darkred]
>>> dir(C)[/color][/color][/color]
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute __', '__hash_
_', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__' , '__repr_
_', '__setattr__', '__str__', '__weakref__']
but it is there:
[color=blue][color=green][color=darkred]
>>> C.__subclasses_ _()[/color][/color][/color]
[]
since it is "acquired" (I don't want to use the word "inherited" ) from
"type":
[color=blue][color=green][color=darkred]
>>> dir(type)[/color][/color][/color]
['__base__', '__bases__', '__basicsize__' , '__call__', '__class__', '__cmp__', '
__delattr__', '__dict__', '__dictoffset__ ', '__doc__', '__flags__', '__getattrib
ute__', '__hash__', '__init__', '__itemsize__', '__module__', '__mro__', '__name
__', '__new__', '__reduce__', '__reduce_ex__' , '__repr__', '__setattr__', '__str
__', '__subclasses__ ', '__weakrefoffse t__', 'mro']
As you see, mro() is another example of meta-method. I shamelessly remind
to http://www-106.ibm.com/developerwork...ary/l-pymeta2/
for more info.
Michele Simionato
> Cool. How come this isn't in either the Language Reference or Library
> Reference? I just skimmed through those looking for special
> class-related methods the other day, when I first started looking at
> prototypes, and didn't notice __subclasses__, and now I can't find it in
> the index.[/color]
Google this newsgroup for __subclasses__. For some reason the
developers choose not to document it, but it is there and it seems to be
working. Just as curiosity, __subclasses__ is a meta-method, i.e. it
is a method of the metaclass "type" and not a class method of "object".
For this reason "dir" does not show it
[color=blue][color=green][color=darkred]
>>> class C(object): pass[/color][/color][/color]
....[color=blue][color=green][color=darkred]
>>> dir(C)[/color][/color][/color]
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute __', '__hash_
_', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__' , '__repr_
_', '__setattr__', '__str__', '__weakref__']
but it is there:
[color=blue][color=green][color=darkred]
>>> C.__subclasses_ _()[/color][/color][/color]
[]
since it is "acquired" (I don't want to use the word "inherited" ) from
"type":
[color=blue][color=green][color=darkred]
>>> dir(type)[/color][/color][/color]
['__base__', '__bases__', '__basicsize__' , '__call__', '__class__', '__cmp__', '
__delattr__', '__dict__', '__dictoffset__ ', '__doc__', '__flags__', '__getattrib
ute__', '__hash__', '__init__', '__itemsize__', '__module__', '__mro__', '__name
__', '__new__', '__reduce__', '__reduce_ex__' , '__repr__', '__setattr__', '__str
__', '__subclasses__ ', '__weakrefoffse t__', 'mro']
As you see, mro() is another example of meta-method. I shamelessly remind
to http://www-106.ibm.com/developerwork...ary/l-pymeta2/
for more info.
Michele Simionato