Figuring out an object's type

David Arnold arnold at dstc.monash.edu.au
Tue May 9 20:56:04 EDT 2000


-->"David" == David Allen <s2mdalle at titan.vcu.edu> writes:

  David> How can a python programmer figure out the type of an object?

the type() function returns the type.  if the object is a class
instance, then it has an attribute __class__ that can be used to
determine its class.

>>> class foo:
...     pass
... 
>>> f = foo()
>>> type(f)
<type 'instance'>
>>> f.__class__
<class __main__.foo at 9dfb8>
>>> f.__class__.__name__
'foo'
>>> 



d




More information about the Python-list mailing list