如何实现classmethod装饰器?
实现 classmethod装饰器
from functools import wraps, partialclass Classmethod: def __init__(self, method): wraps(method)(self) def __get__(self, instance, cls): return partial(self.__wrapped__, cls)class C: @Classmethod def method(cls): print(cls) @Classmethod def method2(cls, x): print(cls) print(x)c =C()c.method()c.method2(1)
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。