EXECing multiple lines.

Joshua Marshall jmarshal at mathworks.com
Mon Jun 11 15:41:11 EDT 2001


Joonas Paalasmaa <joonas at olen.to> wrote:
> What might be wrong when I get the following error?

>>>> exec """for x in range(5):
>     print x"""
> Traceback (innermost last):
>   File "<pyshell#3>", line 1, in ?
>     exec """for x in range(5):
>   File "<string>", line 2
>     print x
>           ^
> SyntaxError: invalid syntax
>>>>

It works if you put a newline at the end.  I don't know if it's a bug
that it doesn't work without the newline.



More information about the Python-list mailing list