[Zope-dev] How to override __getattr__ and not break acquisition

Lennart Regebro lennart@torped.se
Thu, 17 Oct 2002 17:16:17 +0200


From: "John Barratt" <jjb@vivitec.com.au>
> Do you mean it only gets [called] when standard (instance & class based)
> searching methods fail?

Yes. At least, this is what the documentation sais, and it seems to be true
as far as I can see.

> Object Manager doesn't specifically, but Implicit does, you can see it
> if you print out its '__class__.__dict__'.

Ah, OK, I never did any really thorough research in that department.  I
have, in any case, gotten the same results as you, so in that case you
probably need to call Implicits.__getattr__ directly.
I haven't seen any negative effects of not doing this, though.

I'm not well versed enough in how to write python stuff in c, so I don't
understand it very well. Just well enough to not be able to find Implicits
__getattr__. :-)

> Exactly what I need! :-)  Thankfully these methods that I need defined
> at runtime only come from one other object, so it appears I can override
> the __of__ method to work the magic for me in conjunction with
> containment acquisition.

Yup, much better way. __getattr__ is more for if you have a dictionary which
data you want as attributes.