Dear sir,
I am used to developing C program on MSVC7.0 platform.
This is my first time to use Python for calling by C program.
Now, it is hard to deal with the problem about extracting the variable
which be definied in Python. That how can I do?
I have gotten the JPython 's sample that the following code can be looked.
Have anyone help me to obtain same results that be called by Python's C API?
What do I mean?
See attached the following code.
// JPython code
=============== =============== =========
import org.python.util .PythonInterpre ter;
import org.python.core .*;
public class SimpleEmbedded {
public static void main(String []args)
throws PyException
{
PythonInterpret er interp =
new PythonInterpret er();
System.out.prin tln("Hello, brave new world");
interp.exec("im port sys");
interp.exec("pr int sys");
interp.set("a", new PyInteger(42));
interp.exec("pr int a");
interp.exec("x = 2+2");
PyObject x = interp.get("x") ;
System.out.prin tln("x: "+x);
System.out.prin tln("Goodbye, cruel world");
}
}
I would like to re-write those program to Python.
// C Language code =============== ===============
void main() {
Py_Initialize() ;
printf("Hello, brave new world");
PyRun_SimpleStr ing("import sys");
PyRun_SimpleStr ing("print sys");
// interp.set("a", new PyInteger(42));
PyRun_SimpleStr ing("print a");
PyRun_SimpleStr ing("x = 2+2");
// PyObject x = interp.get("x") ;
// System.out.prin tln("x: "+x);
Py_Finalize();
printf("Goodbye , cruel world");
}
See the above C Language code,
After running the statement PyRun_SimpleStr ing("x = 2+2"),
the variable x can be definied and be assigned value 4 in Python.
Meanwhile, next one, I would like to get the x porinter.
Could you help me how can I do?
Or show me the other way to reach my purpose.
Sincerely yours,
Link