regarding memoize function

ankitks.mital at ankitks.mital at
Fri Apr 4 01:33:41 CEST 2008

I saw example of memoize is snippet

def memoize(fn, slot):
       def memoized_fn(obj, *args):
            if hasattr(obj, slot):
                return getattr(obj, slot)
                val = fn(obj, *args)
                setattr(obj, slot, val)
                return val
       return memoized_fn

and I am really clueless, about what it does. I know in general we try
to keep computed values for future usage. But I am having hard-time
visualizing it.
What is obj here? and what does *args means?

More information about the Python-list mailing list