[Pyrex] Does "exec" work in Pyrex?

Phillip J. Eby pje at telecommunity.com
Wed Jun 9 20:26:35 CEST 2004


At 11:22 AM 6/9/04 -0400, Edward C. Jones wrote:
>Does "exec" work in Pyrex? Compiling
>
>def atest():
>    exec 'x = 2.718'
>    print x
>    exec 'cdef y = 3.14'
>    print y
>
>gives the message
>
>pyExample.pyx:2:4: Expected an identifier or literal

I think you just answered your own question.  :)

However, note that even if exec did "work" in the sense of allowing Python 
code to be run, it would:

1) not have access to the locals namespace, because C code doesn't have a 
namespace dictionary

2) not execute Pyrex statements, because it's Python.

If you need to dynamically compile or execute Python code (NOT Pyrex code) 
from within Pyrex, you should use the appropriate Python/C API calls.  See 
the appropriate Python manual for documentation on those calls.  You can 
use any such API by declaring it in an appropriate

     cdef extern from "Python.h":

block.





More information about the Pyrex mailing list