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__

你可能感兴趣的:(python)