Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Getting the class name of an instance

How do I find out the name of the class used to create an instance of an object in Python?

I'm not sure if I should use the inspect module or parse the __class__ attribute.

Answer*

Draft saved
Draft discarded
Cancel
4
  • That's hard to read, are those inline methods I don't know about? Commented Mar 8, 2023 at 15:36
  • If I came across a line such as this, I'd definitely "annotate" the code just to know the name of whom I was going to swear a lot. Commented Aug 31, 2023 at 19:39
  • Or just use type(bar).__qualname__ Commented Jul 9, 2024 at 8:10
  • Too "magical", not readable :) Commented Aug 23, 2024 at 13:26

lang-py

AltStyle によって変換されたページ (->オリジナル) /