I'm defining a few classes dynamically using type()
and placing them in a list as I do so. I would, however, like to make the classes available from the module. That, for example, I can call from factories import PersonFactory
if my module is factories.py
and a dynamic class I create is PersonFactory
.
This is a portion of the code in factories.py
:
factories = []
for name, obj in models:
factory_name = name + 'Factory' # e.g. PersonFactory
attrs = assemble_factory_attrs(obj, factory_name)
f = type(factory_name, (object,), attrs)
factories.append(f)
# I wanted to "release" the classes into the module definition through `*factories`
# but I get this syntax error: "SyntaxError: can use starred expression only as assignment target"
*factories
Thank you!