python类装饰器用法实例
本文实例讲述了python类装饰器用法。分享给大家供大家参考。具体如下:
#!coding=utf-8 registry = {} def register(cls): registry[cls.__clsid__] = cls return cls @register class Foo(object): __clsid__ = '123-456' def bar(self): pass print registry
运行结果如下:
{'123-456': <class '__main__.Foo'>}
希望本文所述对大家的Python程序设计有所帮助。
相关推荐
class Singleton: def __new__: # 关键在于这,每一次实例化的时候,我们都只会返回这同一个instance对象 if not hasattr: cls.instance =
lhxxhl 2020-05-16
codeAB 2020-01-19
FlySky 2020-09-29
Phplayers 2020-09-05
oXiaoChong 2020-06-03
laohyx 2020-04-06
pengkunstone 2020-02-22
逍遥友 2019-12-30
typhoonpython 2019-11-19
amazingbo 2019-06-30
pythonxuexi 2019-06-28
ruoyiqing 2016-10-13
cjb 2019-06-28
小方哥哥 2019-06-27
hualicc 2010-05-04
manbucy 2010-03-03
jibkfv 2019-06-20