How is the execution order of 'x = z'? (also: Python FAQ 4.88)
Terry Reedy
tjreedy at udel.edu
Wed Jul 23 18:34:00 EDT 2003
"Ames Andreas (MPA/DF)" <Andreas.Ames at tenovis.com> wrote in message
news:mailman.1058949155.26009.python-list at python.org...
> Below is a more selfcontained sample (assume that x, y and z are not
> bound before the code is executed):
>
> >>> class Foo:
> ... def __del__(self):
> ... print '__del__(%#x)' % id(self)
> ...
> >>> y = Foo()
> >>> print '%#x' % id(y)
> 0x8152e7c
> >>> z = 0
> >>> print '%#x' % id(z)
> 0x80cbf70
> >>> x = y
> >>> print '%#x' % id(x)
> 0x8152e7c
> >>> del y
> >>> print '%#x' % id(x)
> 0x8152e7c
> >>> x = z
> __del__(0x8152e7c)
> >>> print '%#x' % id(x)
> 0x80cbf70
>
> The assignment 'x = z' calls Foo.__del__. What I wanted to know is:
>
> Is Foo.__del__ called *before* x refers to an integer object of
value
> 0 or *afterwards*. In other words, does x refer to a possibly
> (partially) invalid object while Foo.__del__ is executed, or what is
> the Python FAQ 4.88 referring to (within the final paragraph which
> begins with 'Note:', dealing with atomicity of operations replacing
> objects)?
This appears not to be defined by the language reference and is thus
an implementation specific question. To find out, put 'print type(x)'
in the delete method -- or even 'print x'! Then post answer ;-)
Terry J. Reedy
More information about the Python-list
mailing list