The del statement

Delete names from a namespace, or attributes, members, or slices from an object.

Syntax:

del target list

Deletion is recursively defined very similar to the way assignment is defined. Rather that spelling it out in full details, here are some hints:

  • Deletion of a target list recursively deletes each target, from left to right.

  • 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).

 

Comment:

"It is illegal" Doesn't "del" just flag the name as "local", so you end up getting an UnboundLocalError when using it?

Posted by Fredrik (2006-12-05)

A Django site. this page was rendered by a django application in 0.01s 2010-09-02 15:31:03.566614. hosted by webfaction.