程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Mixed development of Java and python

編輯:Python


1.Java And Python Hybrid development


  1. The language I am proficient in is java,java And python How to realize hybrid development of ,javaEE+python To implement online testing tools . The following is a simple arrangement of ideas .
    ​<dependency><groupId>org.python</groupId><artifactId>jython-standalone</artifactId><version>2.7.0</version></dependency> ​​​​publicclassApp{publicstaticvoidmain(String[] args ){System.out.println("Hello World!");PythonInterpreter interpreter =newPythonInterpreter(); interpreter.exec("a=[5,4,3,2,1]"); interpreter.exec("print sorted(a)");}} ​
  2. The above method is too cumbersome , You can introduce py file
    ​def add(a,b):return a+b if __name__ =='__main__':print add(1,2) ​​​​packagecom.firewolf;importorg.python.core.PyFunction;importorg.python.core.PyInteger;importorg.python.core.PyObject;importorg.python.util.PythonInterpreter;/** * Hello world! * */publicclassApp{publicstaticvoidmain(String[] args ){System.out.println("Hello World!");PythonInterpreter interpreter =newPythonInterpreter(); interpreter.exec("a=[5,4,3,2,1]"); interpreter.exec("print sorted(a)"); interpreter.execfile("src/resources/AddTwoNum.py");PyFunction function = interpreter.get("add",PyFunction.class);// If there is main Method receipt letter main Method .int a =1,b=2;System.out.println(" call py");PyObject pyObject = function.__call__(newPyInteger(a),newPyInteger(2));System.out.println("add The answer is "+pyObject);}} ​



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved