"as" keyword woes

Ben Finney bignose+hates-spam at benfinney.id.au
Thu Dec 4 01:16:49 CET 2008

"Warren DeLano" <warren at delsci.com> writes:

> Why was it necessary to make "as" a reserved keyword?  

I can't answer for the Python developers as to why they *did* make it
a reserved word.

But I can offer what I believe is a good reason why it *should* be a
reserved word: Because simple is better than complex, and special
cases aren't special enough to break the rules.

> And more to the point, why was it necessary to prevent developers
> from being able to refer to attributes named "as"?

There aren't special rules for which names can be use in which way,
and that's a *good* thing. Any name that is valid in one area of
Python syntax is valid in all Python syntax.

> Why can't the parser distinguish between a standalone " as " keyword
> and ".as" used as an object/attribute reference?

Because that would require special-casing some names as being
forbidden in syntax where other names are allowed. Special cases in
language syntax are to be avoided where feasible.

 \         “Pinky, are you pondering what I'm pondering?” “I think so, |
  `\        Brain, but this time *you* put the trousers on the chimp.” |
_o__)                                           —_Pinky and The Brain_ |
Ben Finney

More information about the Python-list mailing list