I would like to have a function that allows generating classes with custom class attributes. Like so:
def test_factory(a):
class Test:
a = a
return Test
However, when I try to call test_factory
, I get an error:
test_factory(1)
> NameError: name 'a' is not defined
The expected behaviour would be:
t1 = test_factory(1)
t2 = test_factory(2)
print(t1.a, t2.a)
> 1, 2
How can I create classes that differ in their class attributes by calling a function?