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)...
阅读全文
摘要: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 = ...
阅读全文
摘要:class Lazyproperty: def __init__(self, func): self.func = func def __get__(self, instance, owner): print('get') # print(instance) # print(owner) if instance i...
阅读全文
摘要: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...
阅读全文
摘要: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_...
阅读全文
浙公网安备 33010602011771号