Dynamic class problem

Robin Becker robin at jessikat.fsnet.co.uk
Wed Jun 6 05:08:16 EDT 2001


In article <LIeT6.2142$G4.314362 at newsc.telia.net>, Fredrik Lundh
<fredrik at pythonware.com> writes
yes I figured out that the try always excepted as Klass isn't visible in
2.0.

My best guess for what I want is

class WKlass(Klass):
    def __getattr__(self,name):
        try:
            return self.__class__.__bases__[0].__getattr__(self,name)
        except:
            return getattr(self._parent,name)

ie I figure it safer to assume that the way to get to an instance's
__bases__ is via its __class__ as the name WKlass will get re-used.

The real intention here is to create a class that wraps an existing
__getattr__ if that's present. If that fails or is absent use the
attribute from the _parent (ie the default attribute holder). I think of
it as chaining the __getattr__ methods.
-- 
Robin Becker



More information about the Python-list mailing list