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

Cliff Wells cliff at develix.com
Wed Sep 13 04:14:39 CEST 2006


On Tue, 2006-09-12 at 18:05 -0700, Robert Hicks wrote:
> metaperl wrote:
> > Istvan Albert wrote:
> > > metaperl wrote:
> > > > -->  python -i
> > > > >>> class = "algebra"
> > > >   File "<stdin>", line 1
> > > >     class = "algebra"
> > > >           ^
> > > > SyntaxError: invalid syntax
> > >
> > > Designing a syntax to avoid all possible newbie errors is impractical
> > > because as soon as you are finished with one iteration the new newbies
> > > will start making different kinds of errors...
> >
> > You are missing the point: the point is that the above could be
> > considered correct if the rules of Python were that an assignment
> > statement takes
> > IDENTIFIER '=' LVALUE
> >
> > Also  "class" IDENTIFIER COLON could also be considered correct.
> >
> 
> Yes it could but it isn't and isn't likely to be. Simply do not use
> reserved words. That rule is hardly limited to Python.

I'm surprised so many people misunderstand his complaint.  It isn't as
simple as "don't do it".  The OP is referring to autogenerated code and
attributes.  This means you must tell the source of the generated items
(perhaps a database table) that it can't have a column named "class" or
"pass" or add hacks in to work around it (an easy one would be to prefix
autogenerated attributes, which also helps work around the lack of
private attributes in Python).

Whether or not this should be changed is tangential to the OP's point.
It must be a bit frustrating to state the obvious over and over and see
it misinterpreted each time.  Python has shortcomings.  This is one of
them, whether there's valid reasons for it or not.  It's better to
acknowledge it and offer something useful rather than "that isn't the
Python way, don't do it."


Cliff

-- 




More information about the Python-list mailing list