Superclasses

Michael Hudson mwh21 at cam.ac.uk
Fri Feb 18 12:39:02 EST 2000


"Joshua C. Marshall" <jayantha at ccs.neu.edu> writes:

> On Thu, 17 Feb 2000, Fredrik Lundh wrote:
> 
> > Joshua C. Marshall <jayantha at ccs.neu.edu> wrote:
> > > Given a class object, is there a way to get at its superclass object?
> > 
> > the thing you're looking for is "__bases__"
> 
> Thanks, that's what I needed.  Incidently, where is "__bases__" defined?  
> If "T" is a class object, doing a "dir(T)" doesn't show "__bases__" as a
> field.
> 

That's because it's a magic attribute; look at Objects/classobject.c
around about line 190 or so.  There is a fairly small set of such
attributes in Python; the "__class__" attribute of instance objects is
similar.

Maybe `dir' should be fixed to add such things.  But it's only a minor
wart.

> Sorry if this is a double-post.  Doesn't seem my last one went through.

It did. But never mind, it wasn't about whitespace!

Cheers,
Michael



More information about the Python-list mailing list