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

Paddy paddy3118 at netscape.net
Wed Sep 13 00:47:01 EDT 2006


Cliff Wells wrote:
> 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
>
> --
Hi Cliff, You would also not be allowed to have a column name with a
space,comma,*,;,... in them. It might be best to assume that column
headings might end up with any arbitrary unicode character string and
program from that.
If the OP knows the full extent of his input data and knows that column
names are valid identifiers PLUS Python reserved words then yes, It
stops him from autogenerating identifiers in tht way - but others in
this thread have suggested work-arounds.

And yes, Python is not perfect, but its sweet spot is oh so tasty :-)

(Which also applies to AWK, for a different sweet flavour)

- Paddy.




More information about the Python-list mailing list