Код: Выделить всё
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Код: Выделить всё
xNot sure if its possible or valid, but is there a way to achieve it ?
Источник: https://stackoverflow.com/questions/781 ... r-metaclas