For logging purposes I want to retrieve the fully qualified class name of a Python object. (With fully qualified I mean the class name including the package and module name.)
I know about x.__class__.__name__
, but is there a simple method to get the package and module?
Best Answer
With the following program
and
Bar
defined asthe output is
If you're still stuck on Python 2, you'll have to use
__name__
instead of__qualname__
, which is less informative for nested classes - a classBar
nested in a classFoo
will show up asBar
instead ofFoo.Bar
: