标签:@class 描述 pre int 定制 利用 UNC div style
利用描述符和类装饰器自定义classmethod方法
class ClassMethod: def __init__(self,func): self.func = func def __get__(self, instance, owner): def deco(*args,**kwargs): self.func(owner,*args) return deco class People: name = ‘qqq‘ @ClassMethod #sayHello = ClassMethod(sayHello) def sayHello(cls,msg): print("你好, %s 帅哥 %s" %(cls.name,msg)) @classmethod def sayHello1(cls,msg): print("你好 %s %s" %(cls.name,msg)) p1 = People() p1.sayHello1(‘sadsad‘) p1.sayHello(‘dsadwqdqw‘) People.sayHello(‘safsaf‘) People.sayHello1(‘sfdsfdsf‘)
标签:@class 描述 pre int 定制 利用 UNC div style
原文地址:https://www.cnblogs.com/xieys-1993/p/11596001.html