Checking if class is derived of some other class
Alexander Skwar
news.ASkwar at DigitalProjects.com
Mon Apr 22 15:43:59 EDT 2002
On Mon, 22 Apr 2002 21:11:59 +0200, Alexander Skwar wrote:
> How can I check if myObject is either directly instantiated from class a
> or is if of a class which inherited from class a?
Okay, figured it out myself:
if issubclass(myObject, a):
print "myObject has some connection to a"
else:
print "no connection between myObject and a"
However, reading
http://www.python.org/doc/current/lib/built-in-funcs.html#l2h-33 ,
I would have thought that the appropriate method would have been
isinstance(). But the following prints "No":
class a:
pass
class b(a):
pass
class c(b):
pass
myObject = c
if isinstance(myObject, c):
print "yes"
else:
print "No"
Why is that?
Alexander Skwar
--
How to quote: http://learn.to/quote (german) http://quote.6x.to (english)
Homepage: http://www.iso-top.de | Jabber: askwar at a-message.de
iso-top.de - Die günstige Art an Linux Distributionen zu kommen
Uptime: 12 hours 46 minutes
More information about the Python-list
mailing list