Are Python's reserved words reserved in places they dont need to be?
Roy Smith
roy at panix.com
Tue Sep 12 23:22:32 EDT 2006
In article <1hlkidf.fm1voc1b64uy5N%aleax at mac.com>,
aleax at mac.com (Alex Martelli) wrote:
> 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
>
Also, keywords are only reserved in the context of identifiers. They can
certainly appear as string literals used as dictionary keys:
attributes["class"] = "algebra"
More information about the Python-list
mailing list