By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,712 Members | 1,591 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,712 IT Pros & Developers. It's quick & easy.

How can I rewrite the JPython to Python?

P: n/a
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() {
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!
printf("Goodbye, cruel world");

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.