class MyMeta(type):
def __init__(self, name, bases, attrs):
pass
def __new__(cls, name, bases, attrs):
attrs['desc'] = lambda self: "the test"
return super().__new__(cls, name, bases, attrs)
class MyMeta(type):
def __init__(self, name, bases, attrs):
self.desc = lambda self: "the test"
def __new__(cls, name, bases, attrs):
return super().__new__(cls, name, bases, attrs)
b = Bar()
print(b.desc())
将desc添加到new和将其添加到init有什么区别?结果是一样的
将desc添加到new和将其添加到init有什么区别?结果是一样的