Search code examples
pythonreflectioninspection

How can I get the name of a python class?


When I have an object foo, I can get it's class object via

str(foo.__class__)

What I would need however is only the name of the class ("Foo" for example), the above would give me something along the lines of

"<class 'my.package.Foo'>"

I know I can get it quite easily with a regexp, but I would like to know if there's a more "clean" way.


Solution

  • Try

    __class__.__name__