How can I rewrite the JPython to Python?

Discussion in 'Python' started by Link, Sep 17, 2003.

  1. Link

    Link Guest

    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");
    }
    Link, Sep 17, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zalek Bloom
    Replies:
    2
    Views:
    741
    llewelly
    Sep 9, 2003
  2. sandip desale
    Replies:
    3
    Views:
    677
  3. sandip desale
    Replies:
    1
    Views:
    559
    Kent Johnson
    May 26, 2006
  4. Sean McCallister

    CPython vs. Jython/JPython

    Sean McCallister, Apr 28, 2007, in forum: Python
    Replies:
    0
    Views:
    317
    Sean McCallister
    Apr 28, 2007
  5. Siegfried Heintze
    Replies:
    6
    Views:
    454
    John J. Lee
    Jul 6, 2007
Loading...

Share This Page