01 2019 档案

摘要:class MyType(type): def __init__(self, a, b, c): print('元类构造函数执行') def __call__(self, *args, **kwargs): obj = object.__new__(self) self.__init__(obj, *args, **kwargs)... 阅读全文
posted @ 2019-01-15 09:56 我爱敲代码 阅读(118) 评论(0) 推荐(0)
摘要:class Foo: def __init__(self, x): self.x = x print(Foo) def __init__(self,x): self.x = x FFo = type('FFo',(object,), {'__init__': __init__}) print(FFo) print(FFo.__dict__) f = ... 阅读全文
posted @ 2019-01-14 22:25 我爱敲代码 阅读(110) 评论(0) 推荐(0)
摘要:class Lazyproperty: def __init__(self, func): self.func = func def __get__(self, instance, owner): print('get') # print(instance) # print(owner) if instance i... 阅读全文
posted @ 2019-01-11 16:25 我爱敲代码 阅读(109) 评论(0) 推荐(0)
摘要:class Type: def __init__(self, key, expect_type): self.key = key self.expect_type = expect_type def __get__(self, instance, owner): print('执行get方法') return in... 阅读全文
posted @ 2019-01-10 09:51 我爱敲代码 阅读(158) 评论(0) 推荐(0)
摘要:import timeclass Foo: x = 1 def __init__(self, y): self.y = y def __getattr__(self, item): # 没有的情况下调用此方法 print(item) def __setattr__(self, key, value): self.__dict_... 阅读全文
posted @ 2019-01-02 20:06 我爱敲代码 阅读(220) 评论(0) 推荐(0)