Deleting objects - my earler post got garbled

Andrew Bennetts andrew-pythonlist at puzzling.org
Fri Apr 23 01:26:29 EDT 2004


On Thu, Apr 22, 2004 at 10:10:14PM -0700, Asun Friere wrote:
> "Martin v. Löwis" <martin at v.loewis.de> wrote in message news:<40883067.4000702 at v.loewis.de>...
> 
> > There is no way to explicitly delete an object in Python.
> 
> So what does "del <object>" actually do then?

As http://docs.python.org/ref/del.html says:

    ...

    Deletion of a name removes the binding of that name from the local or
    global namespace, depending on whether the name occurs in a global
    statement in the same code block. If the name is unbound, a NameError
    exception will be raised.

    It is illegal to delete a name from the local namespace if it occurs as
    a free variable in a nested block.

    Deletion of attribute references, subscriptions and slicings is passed
    to the primary object involved; deletion of a slicing is in general
    equivalent to assignment of an empty slice of the right type (but even
    this is determined by the sliced object).

Essentially, the del statement deletes a reference to an object.  There may
be other references to the object, and even if there aren't the garbage
collector might not collect the object immediately, if at all.

-Andrew.





More information about the Python-list mailing list