2👍
✅
You cannot set it dynamically with setattr
because you are dealing with Python descriptors, not attributes. This is because of the order of events when the module is imported and Python class ans descriptors put together.
Naturally, you can still do this in superious dynamic language like Python. But the solution for the problem needs different approach
-
You can use Python metaclasses and override
__new__
-
See declared_attr in SQLAlchemy, its own way to solve this special case
Source:stackexchange.com