On Sunday, January 16, 2011 9:24:49 AM UTC, Santiago Caracol wrote: > > Hello, > > is there such a thing as "compiled methods" in Django i.e. methods > whose return value is calculated only once and then stored? Or is > there a canonical Djangoish way to implement this? > > An example: > > Suppose we have phone objects that have a canonical form, such as > "alcatel a-341 i" and a paraphrase type p and a method variants() that > calculates all variants of the canonical form, given the paraphrase > type p, such as: > > alcatel a-341 i, alcatel a 341 i, alcatel a341 i, alcatel a-341-i, > alcatel a 341-i, alcatel a341-i, alcatel a-341i, alcatel a 341i, > alcatel a341i, a-341 i, a 341 i, a341 i, a-341-i, a 341-i, a341-i, > a-341i, a 341i, a341i > > Obviously it is very bad for speed to calculate the variants of each > phone object every time the object is needed for some action. > > Santiago > > This is usually known as memoizing, and there are various ways to achieve it. Django actually includes a memoize decorator in django.utils.functional, but you'll find lots of other recipes around the web. -- DR.
-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.