why it is invalid syntax?
J. Clifford Dyer
jcd at sdf.lonestar.org
Thu Nov 22 09:03:40 EST 2007
On Thu, Nov 22, 2007 at 06:47:33AM +0000, Marc 'BlackJack' Rintsch wrote regarding Re: why it is invalid syntax?:
>
> It's quite unreadable and if this would be allowed you would have to
> introduce a special rule to forbid ``else``, ``except`` and ``finally``
> because it can lead to ambiguities. To which ``if`` does the ``else``
> belong to here? ::
>
> if 1: print 1 if: 1 print 1 else: print 1
>
> Ciao,
> Marc 'BlackJack' Rintsch
I don't reckon in matters much. Your output will be:
1
1
;)
No, actually on second inspection your output will be:
File "<stdin>", line 1
if 1: print 1 if: 1 print 1 else: print 1
^
SyntaxError: invalid syntax
But it's a good point.
Cheers,
Cliff
More information about the Python-list
mailing list