我有以下代码:
class ObjectOne(object):
@classmethod
def print_class_name(cls):
print cls.__class__.__name__
def print_class_name_again(self):
print self.__class__.__name__
if __name__ == '__main__':
obj_one = ObjectOne()
obj_one.print_class_name()
obj_one.print_class_name_again()
输出是:
type
ObjectOne
我希望输出为:
ObjectOne
ObjectOne
但我想通过装饰器将其保留test_cls
为类方法。@classmethod
我怎样才能做到这一点?