Question about __getattribute__/__getattr__

Mark McEahern marklists at
Mon Sep 30 18:22:02 EDT 2002

[Joao Prado Maia]
> My question is, how do I get the actual argument list from inside
> __getattr__, so I can create an unique method/argument list signature for
> the cached files ? :)

__getattr__ may not be the ticket.  I can sketch one possibility, but sadly
I don't have time to flesh it out fully:

When you init your Cache class, dynamically build proxy methods for each
method in the cached class.  Something like this:

  import inspect

  class Foo(object):

    def do_something(self, *args, **kwargs):
      # whatever

  class Cache(object):

    def __init__(self, cached_class):
      self._inst = cached_class()

      for m in inspect.getmembers(self._inst, inspect.ismethod):
        # m is a tuple, m[0] is the method name, m[1] is the method
        setattr(self, m[0], MemoizedFunction(m[1]))


// m

More information about the Python-list mailing list