Get the full class name of a Python class (Python 3.3+)

How can I get the class name, including the full path from its module root? For Python 3.3 and above?

Here is a sample Python code:

class A: class B: class C: def me(self): print(self.__module__) print(type(self).__name__) print(repr(self)) x = ABC() x.me() 

This code takes me to Python 3.3:

 __main__ C <__main__.ABC object at 0x0000000002A47278> 

So, Python internally knows that my __main__.ABC object, but how can I get this programmatically? I can parse repr(self) , but it sounds like cracking me.

+5
source share
1 answer

You are looking for __qualname__ (introduced in Python 3.3):

 class A: class B: class C: def me(self): print(self.__module__) print(type(self).__name__) print(type(self).__qualname__) print(repr(self)) 
+5
source

All Articles