What kind of class does my instance belong too?

Mike Fletcher mfletch at tpresence.com
Mon Nov 13 18:23:38 CET 2000


isinstance( object, class )
# also checks for sub-classes, so your check would need to be for the
subclass, not for the superclass...

or

if self.__class__ == Spam:
	# more fragile, since only _exactly_ this class is accepted

HTH,
Mike

-----Original Message-----
From: Peter Stöhr [mailto:peter.stoehr at fh-hof.de]
Sent: Monday, November 13, 2000 1:14 PM
To: python-list at python.org
Subject: What kind of class does my instance belong too?
...
class Eggs(Spam):
    def doSomething(self, aArg):
        if aArg is instance of Spam:
            self.spamIt()
        else:
            seld.doSoemthingDifferent()

What I try to figure out is what is the correct way to write such an
if-statement ?
...




More information about the Python-list mailing list