[Python-Dev] Py_CLEAR and assigning values

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Aug 6 03:03:44 CEST 2008


Paul Pogonyshev wrote:

> 	del obj.x
> 	obj.x = y
> 
> though I'm not sure if for Python code x.__del__ will see obj.x as
> non-set attribute (I guess so, but I'm not sure).

A quick experiment suggests that it does:

Python 2.5 (r25:51908, Apr  8 2007, 22:22:18)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> class Foo(object):
...  def __del__(self):
...   print "__del__"
...   print x.a
...
 >>> x = Foo()
 >>> x.a = Foo()
 >>> del x.a
__del__
Exception exceptions.AttributeError: "'Foo' object has no attribute 'a'" in 
<bound method Foo.__del__ of <__main__.Foo object at 0x6b6f0>> ignored

-- 
Greg


More information about the Python-Dev mailing list