Are Python's reserved words reserved in places they dont need to be?

Alex Martelli aleax at mac.com
Tue Sep 12 23:12:48 EDT 2006


metaperl <metaperl at gmail.com> wrote:

> Diez B. Roggisch wrote:
> > metaperl schrieb:
> > >   -->  python -i
> > >>>> class = "algebra"
> > >   File "<stdin>", line 1
> > >     class = "algebra"
> > >           ^
> > > SyntaxError: invalid syntax
> > >
> > >
> > > Why isn' t the parser smart enough to see that class followed by an
> 
> >  the few reserved words won't matter usually.
> 
> woe be unto the ORMs who try to map database columns to Python
> attributes.

I'm gonna skip my usual anti-ORM rant, because there ARE valid case for
"mapping external names to Python identifiers" -- e.g., remote protocols
such as XML-RPC, automatic constructers of FF interfaces, etc.  Such
code generators -- targeting ANY language currently alive -- obviously
have to possess some minimal knowledge of the target language's syntax,
and the obvious solution is to systematically transform identifiers
which would otherwise be keywords.  The one most popular convention is
to append an underscore -- so that 'pass' becomes 'pass_', and so on.


Alex
 



More information about the Python-list mailing list