(All in ActivePython 3.1.2)
I tried to change the class (rather than instance) attributes. The __dict__
of the metaclass seemed like the perfect solution. But when I tried to modify, I got:
TypeError: 'dict_proxy' object does not support item assignment
Why, and what can I do about it?
EDIT
I'm adding attributes inside the class definition.
setattr
doesn't work because the class is not yet built, and hence I can't refer to it yet (or at least I don't know how).
The traditional assignment doesn't work because I'm adding a large number of attributes, whose names are determined by a certain rule (so I can't just type them out).
In other words, suppose I want class A
to have attributes A.a001
through A.a999
; and all of them have to be defined before it's fully built (since otherwise SQLAlchemy won't instrument it properly).
Note also that I made a typo in the original title: it's __dict__
of a regular class, not a metaclass, that I wanted to modify.