Introspection Class/Instance Name

Roland Heiber newstonne at web.de
Wed Apr 26 02:13:56 EDT 2006


*binarystar* wrote:
> Hello there,
> 
> what method would you use to return the name of the class and/or 
> instance introspectively eg.
> 
> class Bollocks:
>     
>     def __init__( self ):
>        
>         print self.__method_that_returns_class_name__()
>         print self.__method_that_returns_instance_name__()
> 
> 
> instance_of_bollocks    = Bollocks()
> 
> # Which outputs
> 
> 'Bollocks'
> 'instance_of_bollocks'
> 
> 
> 
> I have been scouring the 2.4 docs ... I am sure it is frustratingly simple
> 
> thx in advance
> 
> **

Hi,

take a look at self.__class__.__name__ for the Class-name.

HtH, Roland



More information about the Python-list mailing list