A
ankitks.mital
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?
Thanks
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?
Thanks