Finding the name of a class
Larry Bates
larry.bates at websafe.com
Tue Aug 1 11:38:17 EDT 2006
Kirk Strauser wrote:
> Given a class:
>
>>>> class foo(object):
>>>> pass
>
> how can I find its name, such as:
>
>>>> b = foo
>>>> print something(b)
> 'foo'
>
> I'm writing a trace() decorator for the sake of practice, and am trying to
> print the name of the class that a traced method belongs to. This seems
> like it should be easy, but I think I've been staring at the problem too
> long.
print print b.__class__.__name__ gives what you want
-Larry Bates
More information about the Python-list
mailing list