News for hackers. Stuff that matters.
Re:Dynamically create a type with Python by daeken on Wednesday June 17, 2009 @02:33PM (#662241)
Metaclasses won't fly in this case, since the order of struct members has to be kept. Tried a bunch of things to make it work, but in the end nothing came out cleaner.
Re:Dynamically create a type with Python by jbox on Wednesday June 17, 2009 @08:16PM (#662724)
"Metaclasses won't fly in this case, since the order of struct members has to be kept."

Couldn't you use a creation counter in a metaclasses and assign order to the attributes as they are added? (like Django's forms use to keep track of field order)

Re:Dynamically create a type with Python by lehmannro on Wednesday June 17, 2009 @09:35PM (#662837)
Oh, I didn't think about the order. Django's approach to this issue is really simple and only requires that all your Struct fields are instances of some common base class.

http://code.djangoproject.com/browser/django/trunk/django/fo... creation of the counter on individual fields

http://code.djangoproject.com/browser/django/trunk/django/fo... application of the counter upon field harvesting

Re:Dynamically create a type with Python by daeken on Wednesday June 17, 2009 @09:32PM (#662832)
Huh, I hadn't thought about that... I may be able to pull that off. Thanks for the suggestion.