"as" keyword woes
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Wed Dec 3 17:38:22 EST 2008
On Wed, 03 Dec 2008 22:02:24 +0000, Martin P. Hellwig wrote:
> Warren DeLano wrote:
>> A bottom line / pragmatic question... hopefully not a FAQ.
>>
>> Why was it necessary to make "as" a reserved keyword?
> <cut>
> Because it can be used at the import statement to let the imported thing
> be known under another name?
> Something like:
>
> >>> import xml.etree.ElementTree as ET
Martin, that doesn't answer the OP's question *at all*. Python 2.5 uses
"as" in that way, and it is not a keyword.
>>> import math as MATHS
>>> MATHS
<module 'math' from '/usr/lib/python2.5/lib-dynload/mathmodule.so'>
>>> as = 45
<stdin>:1: Warning: 'as' will become a reserved keyword in Python 2.6
>>> as
<stdin>:1: Warning: 'as' will become a reserved keyword in Python 2.6
45
I'd guess that the change was to simplify the CPython parser. I have no
idea if it was a tiny change or a significant change, if it made a huge
difference to Python-dev or a little difference. Perhaps someone on the
dev team could comment.
While I feel sympathy for the OP, I do have to ask: he's been using
Python 2.5 for, what, a couple of years now? How many times did he see
the depreciation warning, and almost certainly the pending depreciation
warning before that? Python-dev has been talking about making "as" a
keyword since at least Python 2.3. Why wait until after version 2.6 is
released before saying anything?
--
Steven
More information about the Python-list
mailing list