Question about __getattribute__/__getattr__
holger krekel
pyth at devel.trillke.net
Mon Sep 30 19:42:34 EDT 2002
Joao Prado Maia wrote:
> On Mon, 30 Sep 2002, holger krekel wrote:
>
> > The important lines from the above link are:
> >
> > def __call__(self, *args):
> > if not self.memo.has_key(args):
> > self.memo[args] = self.fn(*args)
> > return self.memo[args]
> >
> > and 'args' is a tuple of arguments.
> > 'args[0]' would give you the first argument, for example.
> >
>
> Correct. However, the same is not valid for __getattr__.
For caching a function's results why do you need __getattr__?
It seems you really need another caching policy than the prescribed
memoize pattern. For example, you may implement a dictish object that evicts
old cached values by means of counting accesses, oldest access times
or whatever. I still see no use for expecting __getattr_ to know about
the arguments. Not?
holger
More information about the Python-list
mailing list