Код: Выделить всё
class Meta(type):
def __new__(cls, name, bases, attrs):
# Generate a and b for the object based on x ?
return super().__new__(cls, name, bases, attrs)
class A(metaclass=Meta):
def __init__(self, a, b):
self.a = a
self.b = b
obj = A(x)
Код: Выделить всё
x
Код: Выделить всё
A
Код: Выделить всё
Meta
Код: Выделить всё
a
Код: Выделить всё
b
Код: Выделить всё
__init__
Код: Выделить всё
A
Код: Выделить всё
obj
Код: Выделить всё
x
Not sure if its possible or valid, but is there a way to achieve it ?
Источник: https://stackoverflow.com/questions/781 ... r-metaclas