Figuring out an object's type

David Allen s2mdalle at titan.vcu.edu
Tue May 9 20:40:11 EDT 2000


Hello,

How can a python programmer figure out the type of an object?  I
read the library reference, and the only helpful thing was the type
library

from types import *
type(someObject)

etc.  But types doesn't seem to distinguish between different types
of user defined classes.  I.e. if I say:

class Foobar:
	pass

class Baz:
	pass

x = Foobar()
y = Baz()

then type(x) == type(y) yeilds 1.  

Which kinda sucks.  :)

How do I tell the difference between a Foobar and a Baz? 
Is there some way each class can have a unique typename, so
I can do something like:

def someFunction(arg):
	if type(arg) == SomePredefinedObject:
		doSomething()
	elif type(arg) == Foobar:
		doSomethingElse()

etc.

Any help would be appreciated.
-- 
David Allen
http://opop.nols.com/




More information about the Python-list mailing list