How can I rewrite the JPython to Python?

L

Link

Hello!I am new to Python and I would like to rewrite the following code to
python use to call by C program:// JPython code
=======================================
import org.python.util.PythonInterpreter;
import org.python.core.*;

public class SimpleEmbedded {
public static void main(String []args)
throws PyException
{
PythonInterpreter interp =
new PythonInterpreter();

System.out.println("Hello, brave new world");
interp.exec("import sys");
interp.exec("print sys");

interp.set("a", new PyInteger(42));
interp.exec("print a");
interp.exec("x = 2+2");
PyObject x = interp.get("x");

System.out.println("x: "+x);
System.out.println("Goodbye, cruel world");
}
}


// C Language code ==============================
void main() {
Py_Initialize();
printf("Hello, brave new world");

PyRun_SimpleString("import sys"); PyRun_SimpleString("print sys");
// interp.set("a", new PyInteger(42));
// I can't rewrite,Please Help!

PyRun_SimpleString("print a"); PyRun_SimpleString("x = 2+2");
// PyObject x = interp.get("x");
// I can't rewrite,Please Help!
// System.out.println("x: "+x);

// I can't rewrite,Please Help!
Py_Finalize();
printf("Goodbye, cruel world");
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top