SyntaxError not honoured in list comprehension?

Mark Dickinson dickinsm at gmail.com
Sun Jul 4 04:55:16 EDT 2010


On Jul 4, 9:31 am, jmfauth <wxjmfa... at gmail.com> wrote:
> Python all versions.
>
> It's not a bug, but I'm suprised the following does
> not raise a SyntaxError (missing space between
> '9' and 'for').
>
>
>
> >>> [9for c in 'abc']
> [9, 9, 9]
>
> Side effect: If this behaviour is considered as correct,
> it makes a correct Python code styling (IDLE, editors, ...)
> practically impossible to realise.

Why?  If Python itself has no problem parsing this code, why should it
be so difficult for editors?  Python's grammar is fairly simple:  it's
LL(1) (unlike C's, for example), so can be parsed with only 1 token of
lookahead.

--
Mark



More information about the Python-list mailing list