{"action":"created","issue":{"url":"https://api.github.com/repos/LeeKamentsky/python-javabridge/issues/92","repository_url":"https://api.github.com/repos/LeeKamentsky/python-javabridge","labels_url":"https://api.github.com/repos/LeeKamentsky/python-javabridge/issues/92/labels{/name}","comments_url":"https://api.github.com/repos/LeeKamentsky/python-javabridge/issues/92/comments","events_url":"https://api.github.com/repos/LeeKamentsky/python-javabridge/issues/92/events","html_url":"https://github.com/LeeKamentsky/python-javabridge/issues/92","id":175969605,"number":92,"title":"What all things are possible with this javabridge. ","user":{"login":"Mahesha999","id":4706946,"avatar_url":"https://avatars.githubusercontent.com/u/4706946?v=3","gravatar_id":"","url":"https://api.github.com/users/Mahesha999","html_url":"https://github.com/Mahesha999","followers_url":"https://api.github.com/users/Mahesha999/followers","following_url":"https://api.github.com/users/Mahesha999/following{/other_user}","gists_url":"https://api.github.com/users/Mahesha999/gists{/gist_id}","starred_url":"https://api.github.com/users/Mahesha999/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mahesha999/subscriptions","organizations_url":"https://api.github.com/users/Mahesha999/orgs","repos_url":"https://api.github.com/users/Mahesha999/repos","events_url":"https://api.github.com/users/Mahesha999/events{/privacy}","received_events_url":"https://api.github.com/users/Mahesha999/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-09T09:43:51Z","updated_at":"2016-09-14T14:04:12Z","closed_at":null,"body":"I want to call python from java. I have some requirements:\r\n\r\n- call should be transparent, in the sense that it should not require modifying `.py` file simply to enable it to be called from java\r\n- I want to be able to send arguments of both primitive types (`int`, `String`, `floats` etc.) or non primitive types (`HashMap`,`ArrayList`) from java to python function and receive back the returned object (which may of primitive types or non-primitive types) from python to java.\r\n- I preferably want to stick to CPython instead of Jython \r\n\r\nI earlier tried with Jython which allows very clean call of python function from java without requiring to change python script. I looked something like this\r\n\r\n**py1.py**\r\n\r\n    def square2(list):\r\n        squares = []\r\n            for i in list:\r\n                squares.append(i*i)\r\n        return squares\r\n\r\n**JythonTest.groovy**\r\n\r\n    PythonInterpreter pi = new PythonInterpreter();\r\n    pi.exec(\"from py1 import square2\");\r\n    pi.set(\"integer\", new PyList([1,2,3,4]));   //ArrayList to be passed to python function\r\n    pi.exec(\"result = square2(integer)\");\r\n    PyList result = (PyList)pi.get(\"result\");\r\n    println result    //[1, 4, 9, 16]\r\n    println result[2] //9\r\n\r\nIs similar thing possible with javabridge? Also is there any detailed tutorial about this? What all I found is [this](http://pythonhosted.org/javabridge/java2python.html)."},"comment":{"url":"https://api.github.com/repos/LeeKamentsky/python-javabridge/issues/comments/247023263","html_url":"https://github.com/LeeKamentsky/python-javabridge/issues/92#issuecomment-247023263","issue_url":"https://api.github.com/repos/LeeKamentsky/python-javabridge/issues/92","id":247023263,"user":{"login":"LeeKamentsky","id":660469,"avatar_url":"https://avatars.githubusercontent.com/u/660469?v=3","gravatar_id":"","url":"https://api.github.com/users/LeeKamentsky","html_url":"https://github.com/LeeKamentsky","followers_url":"https://api.github.com/users/LeeKamentsky/followers","following_url":"https://api.github.com/users/LeeKamentsky/following{/other_user}","gists_url":"https://api.github.com/users/LeeKamentsky/gists{/gist_id}","starred_url":"https://api.github.com/users/LeeKamentsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LeeKamentsky/subscriptions","organizations_url":"https://api.github.com/users/LeeKamentsky/orgs","repos_url":"https://api.github.com/users/LeeKamentsky/repos","events_url":"https://api.github.com/users/LeeKamentsky/events{/privacy}","received_events_url":"https://api.github.com/users/LeeKamentsky/received_events","type":"User","site_admin":false},"created_at":"2016-09-14T14:04:12Z","updated_at":"2016-09-14T14:04:12Z","body":"If your computer's Python distribution has pandas and numpy installed, you should be able to go ahead and use them from Java. If you're using a virtual environment, things are more difficult, but possible - I'd rather not go into that unless you need help, but the basic idea is to get things on your sys.path.\r\n\r\nFor your own python function, the best solution is to make a distutils package and install it to your local Python - I'm guessing you just want to load the functions from a single .py file, though. To do that, put the .py file in a directory, e.g. \"/home/mahesha/sources\" and have the following in the Python script that you run:\r\n\r\n    import sys\r\n    script_path = \"/home/mahesha/sources\"\r\n    if script_path not in sys.path:\r\n        sys.path.append(script_path)\r\n\r\nThen later on you can do:\r\n\r\n    from my_file import my_function\r\n    my_function()\r\n\r\nHope this is enough to get things working."}}
{"actor":{"display_login":"LeeKamentsky"}}