The del statement
Sion Arrowsmith
siona at chiark.greenend.org.uk
Tue Dec 5 11:40:12 EST 2006
Marco Aschwanden <PPNTWIMBXFFC at spammotel.com> wrote:
[ ... ]
>> so what about
>>
>> del x
>
>Ups. I never used it for an object. So far I only used it for deletion of
>elements of a container. In that case del has two purposes:
>
>1. Deletes an item from a container (and of course destructs it) -->
>list.remove(elem)
>2. Calls the destructor of an object --> list.destruct()
>
>One statement and two distinct purposes.
Leaving aside the discussion about whether Python has destructors or
not, you are mistaken on two counts:
1. del *is not responsible for an object being destroyed*. That is
done by the garbage collector.
2. del is only ever used to "delete an item from a container". It's
just that in the plain "del x" case, the container is implicitly the
current namespace. (In any case, it's not really "deleting an item
from a container", it's removing a reference to the item from the
container.)
--
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
More information about the Python-list
mailing list