SyntaxError not honoured in list comprehension?

Thomas Jollans thomas at jollans.com
Sun Jul 4 11:08:50 EDT 2010


On 07/04/2010 03:49 PM, jmfauth wrote:
> On 4 juil, 12:35, Carl Banks <pavlovevide... at gmail.com> wrote:
>> On Jul 4, 1:31 am, jmfauth <wxjmfa... at gmail.com> wrote:
>>
> 
> 
> Thanks for having explained in good English my feelings.
> 
> 
>>
>> Some other places were keyword can follow a number:
>>
> 
> Note, that this does not envolve numbers only.
> 
>>>> ['z' for c in 'abc']
> ['z', 'z', 'z']
>>>> 'z'if True else 'a'
> z
>>>>
> 
> 
> 
>>> Side effect: If this behaviour is considered as correct,
>>> it makes a correct Python code styling (IDLE, editors, ...)
>>> practically impossible to realise.
>>
>> I'm not sure why an odd corner of the grammar would mess the whole
>> thing up.  Most code stylers only approximate the actual grammar
>> anyway.
>>
> 
> I guess, most editors (so do I) are mainly using
> a "re" engine for their styling.
> 
> ---
> 
> Not a keyword, but space related, what should I thing
> about this?
> 
>>>> print9

looks like an identifier

> Traceback (most recent call last):
>   File "<psi last command>", line 1, in <module>
> NameError: name 'print9' is not defined
>>>> print+9

can't be a single identifier. Maybe it's a print statement followed by
stuff? (stop being a statement, print!)

> 9
>>>> print'abc'

can't be an identifier or string literal. Maybe it's a print statement
followed by stuff?

> abc
>>>> print9.0

looks like getattr(print9, '0') - but '0' is not a valid name.
Impossible. Error!

>   File "<psi last command>", line 1
>     print9.0
>            ^
> SyntaxError: invalid syntax
>>>>

somewhat strange, yes.




More information about the Python-list mailing list