tags:

views:

117

answers:

1

The title says it mostly.

If I have an object in Python and want to access the name of the class it is instantiated from is there a standard way to do this?

+18  A: 
obj.__class__.__name__
Benji York
Haha, I love it. Succinct.
Andrew Szeto
Except for the annoying underscores (which are a general Python phenomenon).
Matthew Flaschen
Those are annoying?
Benjamin Peterson
Those are uncomfortable.
Sahasranaman MS
What are uncomfortable? The obvious markers that delineate "internal details"? How can those essential markers be uncomfortable?
S.Lott
So I guess __FILE__ and __LINE__ are annoying too? It's not just a Python thing—the underscores are used pretty universally, as far as I know. :/
htw
Yeah, but Ruby is so much more elegant. obj.class.name :)
musicfreak