Python - Django - SimpleLazyObject

Oscar Brito

Cool code from django to execute code when it is needed (lambda is only executed when fn() ):

fn = SimpleLazyObject(lambda: XXXXXXXXXXX )

Some of the guts of the implementation:
from django.utils.functional import SimpleLazyObject
def newmethodproxy(func):
    def inner(self, *args):
        if self.wrapped is empty:
        return func(self.wrapped, *args)
class SimpleLazyObject(LazyObject):
    # Need to pretend to be the wrapped class, for the sake of objects that care
    # about this (especially in equality tests)
    class = property(new

Visit for more informations, contacts and news about Web Development.
See other blog posts at

Divhide purpose is to follow the HTML5 movement and contribute with applications which prove the quality of technology.

Feel free to contact divhide.