python类装饰器用法实例
作者:MaxOmnis 时间:2023-06-25 11:12:38
本文实例讲述了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程序设计有所帮助。
标签:python,类装饰器
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python使用pandas处理CSV文件的实例讲解
2021-01-31 18:23:37
![](https://img.aspxhome.com/file/2023/3/131283_0s.jpg)
一次Mysql死锁排查过程的全纪录
2024-01-16 20:35:53
SQLServer2019配置端口号的实现
2024-01-28 22:29:52
![](https://img.aspxhome.com/file/2023/8/127988_0s.png)
Ubuntu+python将nii图像保存成png格式
2022-05-11 10:04:51
JavaScript中实现块作用域的方法
2024-04-16 10:38:39
javascript实现倒计时提示框
2024-04-22 22:30:35
![](https://img.aspxhome.com/file/2023/2/135682_0s.jpg)
JS组件Bootstrap实现图片轮播效果
2024-04-22 13:03:11
![](https://img.aspxhome.com/file/2023/0/135900_0s.gif)
如何选择合适的MySQL存储引擎
2009-02-04 13:02:00
Python math库 ln(x)运算的实现及原理
2023-09-11 18:12:28
![](https://img.aspxhome.com/file/2023/8/70228_0s.png)
详解Python爬取并下载《电影天堂》3千多部电影
2023-07-07 23:48:24
![](https://img.aspxhome.com/file/2023/2/135312_0s.jpg)
举例简单讲解Python中的数据存储模块shelve的用法
2022-10-12 04:23:55
关于配置babel-plugin-import报错的坑及解决
2023-07-02 16:39:01
![](https://img.aspxhome.com/file/2023/2/139752_0s.png)
制作一个更漂亮一些的多选列表框
2007-10-16 13:04:00
![](https://img.aspxhome.com/file/UploadPic/200710/16/2007101613723940s.gif)
javascript中的数字与字符串相加实例分析
2024-06-05 09:12:13
将python依赖包打包成window下可执行文件bat方式
2022-01-25 08:11:43
Matlab常用的输出命令disp与fprintf解读
2022-03-18 17:13:58
![](https://img.aspxhome.com/file/2023/2/105372_0s.png)
Python中tell()方法的使用详解
2021-06-29 16:21:59
SQL Server 2019自定义安装教程
2024-01-12 21:14:22
![](https://img.aspxhome.com/file/2023/4/94434_0s.jpg)
ASP怎么谈到应用到类的?
2008-03-10 11:21:00
Python Django教程之实现待办事项应用程序
2022-11-13 09:39:15
![](https://img.aspxhome.com/file/2023/0/84870_0s.png)