【发布时间】:2021-12-10 22:28:25
【问题描述】:
这里是示例代码:
from abc import *
class weightlayer(metaclass=ABCMeta):
def __init_subclass__(cls):
cls.count = 0
def __init__(self):
self.order = cls.count
cls.count += 1
@abstractmethod
def init_weight(self):
pass
class A_layer(weightlayer):
def init_weight(self):
pass
class B_layer(weightlayer):
def init_weight(self):
pass
我已经搜索了很多次,但我找不到解决方案。
我的想法不起作用,因为__ init __ 函数没有cls 参数。
我该怎么办?
【问题讨论】:
标签: python python-3.x metaclass python-magic