Answers for "python object name"

2

how to get the name of a class in python

class test:
  @property
  def cls_name(self):
    return self.__class__.__name__
  
  @property
  def cls_name_2(self):
    return type(self).__name__
  
  @classmethod 
	def cls_name_3(cls):
		return cls.__name__
      
ins = test()

print(ins.cls_name)
print(ins.cls_name_2)
print(ins.cls_name_3())
Posted by: Guest on September-10-2021
0

how to get the name of an object in python

dict([(t.__name__, t) for t in fun_list])
Posted by: Guest on February-17-2021
0

python object name

def name_of_object(arg):
    # check __name__ attribute (functions)
    try:
        return arg.__name__
    except AttributeError:
        pass

    for name, value in globals().items():
        if value is arg and not name.startswith('_'):
            return name
Posted by: Guest on October-27-2021

Code answers related to "python object name"

Python Answers by Framework

Browse Popular Code Answers by Language