ast.parse

Kiuhnm kiuhnm03.4t.yahoo.it
Mon Apr 9 09:57:59 EDT 2012


On 4/9/2012 14:43, Irmen de Jong wrote:
> On 9-4-2012 13:53, Kiuhnm wrote:
>> Is it a known fact that ast.parse doesn't handle line continuations and some multi-line
>> expressions?
>> For instance, he doesn't like
>>      for (x,
>>           y) in each([1,
>>                       2]):
>>          print(1)
>> at all.
>> Is there a workaround besides "repairing" the code on the fly?
>>
>> Kiuhnm
>
> What Python version are you using and what is the exact error? It works fine here
> (Python 2.7.2):
>
>>>> import ast
>>>> code="""for (x,
> ...          y) in each([1,
> ...                      2]):
> ...         print(1)"""
>>>> ast.parse(code)
> <_ast.Module object at 0x02418A10>

Yes, it works. I was too hasty in blaming ast. Sorry.

Kiuhnm



More information about the Python-list mailing list