标签:font 调用 hat __new__ rgs idea 链接 字典 eth
class PeopleBase(six.with_metaclass(ABCMeta, object)): @abstractmethod def work(self, *args, **kwargs): #pass为空语句,占位用 pass @abstractmethod def live(self, *args, **kwargs): pass
def with_metaclass(meta, *bases): """Create a base class with a metaclass.""" # This requires a bit of explanation: the basic idea is to make a dummy # metaclass for one level of class instantiation that replaces itself with # the actual metaclass. class metaclass(type): def __new__(cls, name, this_bases, d): return meta(name, bases, d) @classmethod def __prepare__(cls, name, this_bases): return meta.__prepare__(name, bases) return type.__new__(metaclass, ‘temporary_class‘, (), {})
print(type(PeopleBase)) print(PeopleBase.__class__) #<class ‘abc.ABCMeta‘> #<class ‘abc.ABCMeta‘>
关于six.with_metaclass(ABCMeta, object)的理解
标签:font 调用 hat __new__ rgs idea 链接 字典 eth
原文地址:https://www.cnblogs.com/zhaoshizi/p/9180886.html