How to find the classname of an object? (was Python Documentation)

Farshid Lashkari lashkariNO at SPAMworldviz.com
Thu May 12 19:30:21 EDT 2005


This will get the name of an objects class

obj.__class__.__name__

This will return a tuple of its base classes

obj.__class__.__bases__

Christopher J. Bottaro wrote:
> I actually want all the parent classes too.  So if D derives off C derives
> off B derives off A, I ultimately want a tuple ('D', 'C', 'B', 'A').
> 
> For those of you following the Python Documentation thread, this is a good
> example of how the PHP manual is "better".  I found how to do this in a few
> seconds in PHP.  I searched the Python docs for "class name", "classname",
> "introspection" and "getclass".  I looked in the Class section of the
> tutorial also and also the Programming FAQ.  The "related functions"
> section of the PHP manual is really helpful.  It would be cool if in the
> section for the built-in function isinstance() or issubclass() there is a
> section for "related functions" that would point me to getclassname(obj)
> (if it exists).
> 
> Thanks for the help.
> 
> -- C
> 



More information about the Python-list mailing list