Python Grammar (was Re: A TYPICAL NEWBIE MISTAKE?)

Thomas Mangin thomasm at legend.co.uk
Sat May 20 12:55:56 CEST 2000


> > > > Erm, how would you parse this?
> > > >
> > > >     if yes ()
> >
> > I would say that seni-colon have *only* to be use to separate condition
from
> > instruction, so this is :
> > if yes ():
> >     _
>
> But maybe it means:
> if yes: ()
>
> Which is perfectly valid Python:
>
> >>> yes = 1
> >>> if yes: ()
> ...
> ()

Not if the grammar specify

VALID : if <condition> <return>
VALID : if <condition> : <instruction(s?)> <return>
INVALID : if <condition> <instruction> <return>

in this case you can not have:
if yes ()
condition : yes
instruction : ()
which is invalid

I really do think this is the best way to do (at least the one I would like
to see)

Thomas







More information about the Python-list mailing list