How can I pass the value of Python variable to C? I compile by this: gcc -I/usr/include/python2.7 ABC.c -lpython2.7 -lm -lutil -lpthread -ldl
#include <Python.h> #include <stdlib.h> #include <import.h> #include <graminit.h> #include <pythonrun.h> int main() { PyObject *pValue, *c, *d; Py_Initialize(); long *b; printf("1+1:\n"); PyRun_SimpleString("print 1+1"); printf("Load sage \n"); PyRun_SimpleString("from sage.all import *"); PyRun_SimpleString("pValue=2"); PyRun_SimpleString("print 'g', pValue"); PyRun_SimpleString("A=[0]*10"); PyRun_SimpleString("for i in range(10):\n" " A[i]=i*i\n"); PyRun_SimpleString("print 'g', A[6]"); d = PyInt_FromLong(40); PyRun_SimpleString("c=pValue+1"); PyRun_SimpleString("print 'c', c"); d=c; printf("Returned val: %ld\n", PyInt_AsLong(d)); Py_Finalize(); return 0; } -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.