where does 'del' come from?

Jim Meier fatjim at home.com
Tue Jun 8 02:56:15 EDT 1999


sragsdale at my-deja.com wrote:

> A fairly academic question, but I'm curious nonetheless.  Where is 'del'
> defined?  Functions like 'join' are obviously in the string package,
> 'range' is a builtin, but I can't seem to find 'del' anywhere.
>
> Python 1.5.2 (#12, Jun  2 1999, 19:23:30) [C] on irix646
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> dir(__builtins__)
>

[snipped list of python builtins, which include the range function and don't
include "del"]

> >>> range
> <built-in function range>
> >>> del
>   File "<stdin>", line 1
>     del
>        ^
> SyntaxError: invalid syntax

The SyntaxError is the clue, as should del's invocation (parentheses-less).
del is not a function, but a part of the Python grammar, the same way if,
while, and, is, etc.. are. If you'd like to see where it comes from, have a
look in your Python source tree:

(python source home)/Grammar/Grammar

I think that should answer the question. Until you start wanting to know how
Python turns the grammar file into an working Python lexer/parser.. that
one's for the CS guys. And I'm not yet a CS guy!

-Jim






More information about the Python-list mailing list