Wow: list of immediate subclasses?

Michael Hudson mwh at python.net
Tue Aug 5 14:48:31 CEST 2003


"Andrew Dalke" <adalke at mindspring.com> writes:

> Michael Hudson:
> > >>> A.__dict__['__weakref__'].__objclass__ is A
> 
> Ahhh...

And *then* I find how I should have found <wink> the cycle:

>>> class A(object): pass
... 
>>> pprint.pprint([r for r in gc.get_referrers(A) if r is not __main__.__dict__])
[<attribute '__dict__' of 'A' objects>,
 <attribute '__weakref__' of 'A' objects>,
 (<class '__main__.A'>, <type 'object'>)]

Forgot about the obvious A.__mro__[0] is A cycle!

Cheers,
mwh

-- 
  A difference which makes no difference is no difference at all.
                        -- William James (I think.  Reference anyone?)




More information about the Python-list mailing list