3 ms·
Creating a new class in Python at run time is pretty easy with the three-argument form of the type function: >>> NewClass = type('NewClass', (), {'foo':42})
by kazinator 3y ago
Creating a new class in Python at run time is pretty easy with the three-argument form of the type function:
>>> NewClass = type('NewClass', (), {'foo':42})
>>> x = NewClass()
>>> x.foo
42