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