Why won't exec accept this?

Stuart Ford Stuart.Ford at Boeckh.com
Wed Jun 28 16:13:22 EDT 2000


Gene <gchiaramonte at mail.com> wrote in message
news:<RCs65.11832$_b3.285418 at newsread1.prod.itd.earthlink.net>...
> I am trying to store scripts in a dictionary, then exec the scripts as
> necessary. I have stored the following text in a dictionary:
> 
> # test ...
> def FooBar(x):
>     return x + x
> 
> # here is the dictionary...
> {'script': '# test ...\015\012def FooBar(x):\015\012    return x + x',
> 'version': 1.0, 'type': 'script'}
> 


This version works for me...

I had to also add the newline after the return statement, 
or exec returned a syntax error.

{'script': '#test ...\ndef FooBar(x):\n  return x+x\n', 
'version':1.0, 'type':'script'}

After the exec, the new function will be created in 
the namespace.

Stuart




More information about the Python-list mailing list