摘要: python 中常见的魔术方法: 1、__init__(self, item):方法 在实例化对象时自动执行,多用于对对象属性进行初始化。 2、__new__(cls,item):方法 实例化对象时自触发,在__init__ 方法之前执行,作为控制对象的生成过程,实现单例设计模式。 3、__del_ 阅读全文
posted @ 2019-08-14 17:52 wxl106 阅读(382) 评论(0) 推荐(0) 编辑
摘要: class Struct(dict): """ Object-Dict >>> o = Struct({'a':1}) >>> o.a >>> 1 >>> o.b >>> None """ def __init__(self, *e, **f): if e: self.update(e[0]) if 阅读全文
posted @ 2019-08-14 16:28 wxl106 阅读(412) 评论(0) 推荐(0) 编辑