Dynamically altering __init__
Kääriäinen Anssi
anssi.kaariainen at thl.fi
Sun Nov 13 07:28:16 EST 2011
I wrote:
"""
I will post a link to a complete example once I have done the AST
transformations etc. I hope this will be useful to readers of this list.
I didn't find such an example, so maybe the next asker will find it...
"""
Finally got time to do this. The example can be found at:
https://github.com/akaariai/ast_model
In the example I rewrote a small part of Django's model __init__ to
use:
self.field1, self.field2, ... = args
instead of:
for f_name, val in izip(field_names, args):
setattr(self, f_name, val)
The speedup of that rewrote is about 50% for a model having 10 fields.
The example implementation might not be optimal, but it seems to
work. I hope it will be useful to the readers of this list. It was a nice
learning experience for me.
Thanks for your help,
- Anssi Kääriäinen
More information about the Python-list
mailing list