Why is "as" not a keyword?

Tim Peters tim.one at home.com
Fri Jan 19 05:56:48 EST 2001


[Jesse W]
> Most people know about the functionality of the import statement that
> lets you import something under a differnt name.  It uses the word "as"
> to tell the interpreter.

Yes, that's a recent addition to the language.

> Why is "as" not a keyword?

Because-- and unlike "in" and "from" --it's a *recent* addition to the
language.  Keywords are reserved words in Python:  you cannot use them for
any other purpose.  Making "as" a keyword at this late stage would have
broken any existing program that happened to already use "as" for its own
purposes (vrbl name, class name, whatever).

> ...
> Currently, it seems to me to be confusing when you type
> 	import foo as bar
>  in IDLE, and import lights up as a keyword, but "as", which has to be
> there and is clearly part of the syntax, does not.

Yup!  In 2.1 alpha 1 (due out Real Soon), I fiddled IDLE to color each word
instance of "as", in "import ..." and "from xxx import ..." statements, and
on the same physical line following the "import" part, as if it were a
keyword.  This is a cheap approximation to the truth.  It's not worth
getting much fancier than that (IDLE can't afford to do a "real parse" -- it
uses an excruciating bag of regexp tricks, and regexps aren't good for
capturing the full truth here).

Barry (Warsaw) also recently fiddled the Emacs pymode to do something
similar.

Don't know about anything else.

really!-don't-know-about-*anything*-else!-what?-ly y'rs  - tim





More information about the Python-list mailing list