总结:自由度不够高,耦合性太强,且尚不得知py文件间存在依赖是否会引发问题。
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("C:\\Python27\\programs\\my_utils.py");
PyFunction func = (PyFunction) interpreter.get("adder",
PyFunction.class);
int a = 2010, b = 2;
PyObject pyobj = func.__call__(new PyInteger(a), new PyInteger(b));
System.out.println("anwser = " + pyobj.toString());
参考链接:
https://blog.csdn.net/cafebar123/article/details/79394431
https://www.cnblogs.com/xuaijun/p/7986003.html
python的rest框架主要有:
flask教程的参考链接:
使用方式大致如下:安装flask—import flask—定义方法并在方法上加路径注解等—启动服务
import json
from flask import Flask
from flask import request
from flask import redirect
from flask import jsonify
app = Flask(__name__)
@app.route('/' , methods=['GET', 'POST'])
def index():
if request.method == 'POST':
a = request.get_data()
dict1 = json.loads(a)
return json.dumps(dict1["data"])
else:
return '只接受post请求!
'
@app.route('/user/')
def user(name):
return'hello, %s
' % name
if __name__ =='__main__':
app.run(debug=True)
此外,flask支持json的数据传输,这就解决方案一自由度不够高、不够灵活的问题了,参考链接:
https://segmentfault.com/a/1190000007605055
flask的拓展库flask restful
https://www.cnblogs.com/wbin91/p/5927506.html