在java类中直接执行python语句
class="highlight">
import org.python.util.PythonInterpreter;
/**
* Created by wjf on 2018/3/16.
*/
public class java2python {
public static void main(String[] args) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("# coding=utf-8");
interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); ");
interpreter.exec("print days[1];");
}
}
public static void main(String[] args) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("C:\\Users\\wjf\\IdeaProjects\\javaTestPython\\src\\my_utils.py");
PyFunction func = interpreter.get("adder", PyFunction.class);
int a = 2010, b = 8;
PyObject pyobj = func.__call__(new PyInteger(a), new PyInteger(b));
System.out.println("anwser = " + pyobj.toString());
}
public static void main(String[] args) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("C:\\Users\\wjf\\IdeaProjects\\javaTestPython\\src\\input.py");
}免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理