当前位置:网站首页>将实例化对象的方法 给新的对象用
将实例化对象的方法 给新的对象用
2022-04-23 06:57:00 【A1L__】
将实例化对象的方法 给新的对象用
class SharedKls:
def __setattr__(self, key, value):
if not hasattr(SharedKls, key):
if callable(value): # 是否可以调用
# 不加staticmethod,会默认传self
value = staticmethod(value)
setattr(SharedKls, key, value)
kls_a = SharedKls()
kls_b = SharedKls()
kls_a.attr_a = 1
def func(self, x):
return x * x
kls_a.method_a = lambda x: x * 3
assert kls_b.method_a(3) == 9
版权声明
本文为[A1L__]所创,转载请带上原文链接,感谢
https://blog.csdn.net/A1L__/article/details/124307542
边栏推荐
- Attack and defense world misc questions 1-50
- 学fpga(从verilog到hls)
- MySQL -- the secret of lock -- how to lock data
- Introduction to sap query enhanced development
- Research on software security based on NLP (2)
- Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)
- [programming practice / embedded competition] learning record of embedded competition (II): picture streaming based on TCP
- 如何在SQL Server中导入excel数据,2019版
- PHP generates short links: convert numbers to letters and letters to numbers
- Research on system and software security (3)
猜你喜欢
随机推荐
数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲
[programming practice / embedded competition] learning record of embedded competition (I): establishment of TCP server and web interface
How does feign integrate hystrix
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
智能名片小程序名片详情页功能实现关键代码
Mobile terminal layout (3D conversion, animation)
C语言学习记录——삼십팔 字符串函数使用和剖析(2)
User manual of Chinese version of solidity ide Remix
Intranet penetration series: dns2tcp of Intranet tunnel
Talking about distributed storage from ES, mongodb, redis and rocketmq
Briefly describe the hierarchical strategy of memory
利用sqlmap注入获取网址管理员账号密码
1216_MISRA_C规范学习笔记_控制流的规则要求
KCD_ EXCEL_ OLE_ TO_ INT_ Convert reports an error sy subrc = 2
访问数据库的时候出现错误 Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY.详解
在线YAML转XML工具
每周leetcode - 06 数组专题 7~739~50~offer 62~26~189~9
MySQL -- the secret of lock -- how to lock data
yum源仓库本地搭建的两种方法
1+x云计算中级--脚本搭建读写分离