__init__ is the initialiser

Chris Angelico rosuav at gmail.com
Mon Feb 3 00:27:51 CET 2014


On Mon, Feb 3, 2014 at 10:15 AM, Gregory Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> Roy Smith wrote:
>>
>> In article <52ec84bc$0$29972$c3e8da3$5496439d at news.astraweb.com>,
>>  Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
>>
>>> A dubious analogy, since there are artists who would say that attacking
>>> the canvas with a knife and setting the remains on fire count as a form of
>>> artistic creation :-)
>>
>>
>> That's __del__()
>
>
> But it only works if the canvas is not referenced
> anywhere in any art catalogues. Otherwise the
> canvas fails to catch fire, and gets put on a
> list of list of artworks to be considered for
> manual incineration.

What you see here is proof that Python really does need an explicit
destroy() function. It would need to recycle the object [1], forcing
all references to it to dangle:

>>> a = object()
>>> b = a
>>> destroy(a)
>>> c = b

Traceback (most recent call last):
  File "<pyshell#89>", line 1, in <module>
    c = b
SegmentationError: dereferencing a dangling pointer

It's a serious lack in Python. Currently it's not possible to do this
without fiddling around in ctypes.

ChrisA

[1] Scrub the RAM clean and return it to the computer, put the 1 bits
onto the stack for subsequent reuse, and throw all the useless 0 bits
out onto the heap.



More information about the Python-list mailing list