Python – Get Object’s Class Name | Ridge Solutions, Ireland

Python – Get Object’s Class Name | Ridge Solutions, Ireland

Q: How do I get a python object’s class name?

 

A: Use the object’s __class__ attribute and then get its __name__ attribute.

 

Another python introspection gem, to get an object’s class name just access its __class__ attribute, for example you can define a method to return the object’s name as follows:

def get_runtime_type_name(self):
  return self.__class__.__name__
上一篇:转:aliyun阿里云Maven仓库地址——加速你的maven构建


下一篇:IntelliJ Idea 依赖包下载成功,代码里无法import问题解决方法