Arg. Silly question!
Andrew Dalke
dalke at acm.org
Sat May 6 02:52:05 EDT 2000
Courageous wrote:
>I have two different types of things that I want to do:
>
>1. Figure out if an object is inherited from a particular
> class.
>
>3. Figure out if an object is an instance of a particular
> class.
Looks like there's a missing 2. ?
Anyway, this might help:
>>> class Spam:
... pass
...
>>> class Eggs(Spam):
... pass
...
>>> spam = Spam()
>>> eggs = Eggs()
>>> isinstance(spam, Spam)
1
>>> isinstance(spam, Eggs)
0
>>> isinstance(eggs, Spam)
1
>>> issubclass(spam.__class__, eggs.__class__)
0
>>> issubclass(eggs.__class__, spam.__class__)
1
>>> eggs.__class__ == Spam
0
>>> eggs.__class__ == Eggs
1
>>>
Some documentation is at
http://python.org/doc/current/lib/built-in-funcs.html#l2h-130
Andrew
dalke at acm.org
More information about the Python-list
mailing list