regarding memoize function

Dan Bishop danb_83 at yahoo.com
Thu Apr 3 20:21:11 EDT 2008


On Apr 3, 6:33 pm, ankitks.mi... at gmail.com wrote:
> I saw example of memoize function...here is snippet
>
> def memoize(fn, slot):
>        def memoized_fn(obj, *args):
>             if hasattr(obj, slot):
>                 return getattr(obj, slot)
>             else:
>                 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?

*args is Python's syntax for variadic functions.



More information about the Python-list mailing list