LoginSignup
5
2

More than 5 years have passed since last update.

TL;DR

jython経由でGroovyからPython2系を実行できる。

環境

Groovy 2.4.7
JVM 1.8.0_111
Python 2.7.5 (GCC4.8.5)

端的に言うとConoHaのCentOS 7で普通に構築すると入るもの。

いきなりコード

jython_test.groovy
@Grab("org.python:jython-standalone:2.7.0")

import org.python.util.PythonInterpreter

def interpreter = new PythonInterpreter()

interpreter.exec("a = 1 + 2")
interpreter.exec("print(a)")

インタープリターにまるっと渡して評価してるっぽい(気がする)

動機とか感想とか

G*カレンダーが一日分未投稿だったので何か書こうと思った。
そこで、私の興味の対象がPython周りに集中してたので、GroovyからPython呼べれば(私が)めっちゃ楽になるという理由で、呼ぶ方法を調べた。
結果、拍子抜けするほど簡単だった。Jythonのインタフェース作ってくれた人や、ノウハウ書いてくれた人達ありがとう!

参考

JythonでJavaからPythonを使う。あとハマったこと。
http://qiita.com/ota-meshi/items/76f4a65e9bd2fe0e2f68

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2