Re: Intercepting __getattr__ in a Python 2.3 old-style mixin class?
Hanno Schlichting <[email protected]> Mon, 07 Nov 2016 15:29:10 +0100
| Newsgroups | gmane.comp.web.zope.devel |
|---|---|
| Message-ID | <1478528950.1669811.779887729.4B949254@webmail.messagingengine.com> |
On Mon, Nov 7, 2016, at 14:01, Andreas Jung wrote: > Python 2.7 is different because all classes are automatically new-style > classes. > In Python 2.7 you would have to overwrite __getattribute__() but I am on > Python 2.3 here. No :) In Python 3 all classes are new-style classes. In Python 2 (including 2.7) you have to be explicit and either inherit from object (new-style) or not (old-style). In Python 2.7 you get: >>> class A: pass >>> class B(object): pass >>> type(A) <type 'classobj'> >>> type(B) <type 'type'> In Python 3 both are of type 'type'. And only new-style classes use '__getattribute__'. '__getattr__' is the right approach for old-style classes in any Python 2 version, even in Python 2.7. Hanno _______________________________________________ Zope-Dev maillist - [email protected] https://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope )