Is " a is b " and " id(a) == id(b) " the same?

Aahz aahz at pythoncraft.com
Sun Mar 16 22:05:46 CET 2003


In article <Xp1da.94293$zo2.2505671 at news2.tin.it>,
Alex Martelli  <aleax at aleax.it> wrote:
>
>Yep -- you can also explicitly define attributes that are generated
>on the fly at each access and ensure this behavior (method objects
>currently _are_ generated on the fly at each access, but it's quite
>permissible for the language implementation to change and cache them
>in some cases in the future).  E.g., try:
>
>class X(object):
>    def __getattr__(self, name):
>        if name == 'f': return []
>        raise AttributeError, name
>
>or
>
>class Y(object):
>    def getf(self): return []
>    f = property(getf)
>
>NOW, after a=X() or a=Y(), you can choose to:
>
>    assert a.f is not a.f

s/__getattr__/__getattribute__/
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Register for PyCon now!  http://www.python.org/pycon/reg.html




More information about the Python-list mailing list