Passing array from java to python

Discussion in 'Python' started by loial, Jun 2, 2011.

  1. loial

    loial Guest

    I need to pass some sort of array or hashmap from Java and read the
    data in a python script (which will be called by the java class). Is
    there any neater way to do this other than just passing strings?
     
    loial, Jun 2, 2011
    #1
    1. Advertising

  2. loial

    Chris Rebert Guest

    On Thu, Jun 2, 2011 at 2:54 AM, loial <> wrote:
    > I need to pass some sort of array or hashmap from Java and read the
    > data in a python script (which will be called by the java class). Is
    > there any neater way  to do this other than just passing strings?


    Jython?: http://www.jython.org/

    Or depending on how you define "just passing strings", JSON:
    http://json.org/
    http://docs.python.org/library/json.html

    Cheers,
    Chris
     
    Chris Rebert, Jun 2, 2011
    #2
    1. Advertising

  3. loial

    loial Guest

    Unfortunately using jpython or json are not options at the moment
     
    loial, Jun 2, 2011
    #3
  4. loial

    Chris Rebert Guest

    On Thu, Jun 2, 2011 at 3:47 AM, loial <> wrote:
    > Unfortunately using jpython or json are not options at the moment


    What rules out JSON that does not also rule out the "just passing
    strings" approach?

    What about (*shudder*) XML? (Can't believe I just said that...)

    Cheers,
    Chris
     
    Chris Rebert, Jun 2, 2011
    #4
  5. loial

    Ian Kelly Guest

    On Thu, Jun 2, 2011 at 4:47 AM, loial <> wrote:
    > Unfortunately using jpython or json are not options at the moment


    How about JPype? Or do the Java and Python need to be in separate processes?
     
    Ian Kelly, Jun 2, 2011
    #5
  6. loial

    Marco Nawijn Guest

    On Jun 2, 11:54 am, loial <> wrote:
    > I need to pass some sort of array or hashmap from Java and read the
    > data in a python script (which will be called by the java class). Is
    > there any neater way  to do this other than just passing strings?


    I recently had to deal with the same problem, some bi-directional
    communication between Java and Python. Several options were discussed
    between me and my fellow programmer. In the end we settled for XML-
    rpc. It works remarkably well in our case. We use it to pass test and
    simulation data to GUI code. XML-rpc is very well supported in python.
    Basic types (lists, dicts etc.) are encoded automatically. If the
    arrays are very large, I would probably use an intermediate database
    (e.g. Hdf5) for storage and then use some sort of messaging to inform
    the Java code of any changes.
     
    Marco Nawijn, Jun 3, 2011
    #6
    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. Replies:
    9
    Views:
    596
    justanotherguy
    Dec 3, 2004
  2. Jonathan Underwood
    Replies:
    2
    Views:
    694
    Simon Biber
    Aug 13, 2003
  3. JW
    Replies:
    1
    Views:
    500
    David Jeske
    Jul 12, 2003
  4. J W
    Replies:
    0
    Views:
    405
  5. deadpickle
    Replies:
    1
    Views:
    1,096
    Jens Thoms Toerring
    Nov 7, 2010
Loading...

Share This Page