Anyways, the idea is the following: you want to change the class attributes before it becomes final -- there are things you just can't do in Python after a class is already declared (Python uses this technique for creating properties -- in my specific use-case I'm using it to overcome some limitations that Django has in its model inheritance with fields, but I've already used this many times).
The idea is the following: you get the frame which is being used inside the class declaration and change the locals in it so that the final created class will have the things you declared.
I.e.: This code:
import sys def prototype_class(frame=None): if frame is None: frame = sys._getframe().f_back frame.f_locals['new_attribute'] = 'New attribute' class MyNewClass(object): prototype_class() print MyNewClass().new_attribute
Is the same as:
class MyNewClass(object): new_attribute = 'New attribute'
-- Just more complicated and more flexible -- in my case, it'll properly help me to choose how to create and customize the fields of a Django model class without having to copy and paste a bunch of code.
On a separate note, blogspot just sucks for code... why can't they simply create an option to add a piece of code? I'm now manually putting my code in html as described in http://stackoverflow.com/a/8697421/110451 -- it'd certainly be trivial for the blogspot devs to put a button which would do that for me right? (colors would be nicer, but this is the easiest things that just works for me and I'd already settle for it if blogger added it -- I know blogger has the quotes, but I want the code at least on a box with a monospaced font).