Newbie question: how to determine "is-a" relationship

Remco Gerlich scarblac at pino.selwerd.nl
Thu Apr 19 19:07:19 EDT 2001


Robert Roy <rjroy at takingcontrol.com> wrote in comp.lang.python:
> On Thu, 19 Apr 2001 10:46:53 -0500, "Jake Baker" <jbaker at ummelec.com>
> wrote:
> 
> >Gosh. I've been using Python since 96 and I don't know this! Wow!
> >
> >Say I have a class heirarchy that looks like A, B <- A, C <- A, etc....
> >
> >I have a list of objects (which I know arbitrarily are all A or sublasses =
> >of A) and want to filter them based on which subclass they are.
> >
> >How do I go about doing this? You help is greatly appreciated!
> >
> >Thanks,
> > - Jake Baker
> 
> I think that instanceof will do the trick. See the Python Library
> Reference under Built-in Functions (Doc\lib\built-in-funcs.html)

Just a slight correction, the function is called 'isinstance'.

He could also look directly at the objects' __class__ member, or even
__bases__.

-- 
Remco Gerlich



More information about the Python-list mailing list