摘要:
class Test(object): def __getattr__(self, item): print('没有找到属性时,触发AttributeError异常时会调用此方法') return f"没有找到 {item} 属性时 ,会调用此方法" def __setattr__(self, ke 阅读全文
posted @ 2025-09-04 21:36
大海一个人听
阅读(14)
评论(0)
推荐(0)
摘要:
def wrapper(cls): instance ={} #创建一个字典用来存放创建出来的单列对象 def _fun(*args,**kwargs): #判断该类在不在字典中, if cls not in instance: #没创建就创建一次,并把它加入到字典中 instance[cls]=c 阅读全文
posted @ 2025-09-04 16:47
大海一个人听
阅读(6)
评论(0)
推荐(0)
摘要:
class Test(object): def __init__(self,name,age): self.name = name self.age = age def __add__(self, other): print('测试一下int 对象的相加') print('对象之间使用了+号') p 阅读全文
posted @ 2025-09-04 16:40
大海一个人听
阅读(8)
评论(0)
推荐(0)
摘要:
class Test(object): def __init__(self,name,age): self.name = name self.age = age def __add__(self, other): print('测试一下int 对象的相加') print('对象之间使用了+号') p 阅读全文
posted @ 2025-09-04 16:34
大海一个人听
阅读(8)
评论(0)
推荐(0)
摘要:
写一个简单的打开文件进行日志记录的单例模式 class Logger: __instance = None def __new__(cls, *args, **kwargs): if not cls.__instance: cls.__instance = super().__new__(cls) 阅读全文
posted @ 2025-09-04 10:34
大海一个人听
阅读(12)
评论(0)
推荐(0)

浙公网安备 33010602011771号