您的位置:首页 > 编程语言 > Python开发

Java执行Python脚本并传参

2017-02-04 00:00 323 查看

Java代码:

public class JavaExePython {

public static void run(String filePath, String param) throws IOException, InterruptedException {
String[] argv = {filePath, param};
PythonInterpreter.initialize(System.getProperties(), System.getProperties(), argv);
PythonInterpreter interpreter = new PythonInterpreter();
PySystemState sys = Py.getSystemState();
sys.path.add("C:\\workspace\\python\\mypython");
sys.path.add("C:\\Python27\\Lib\\site-packages");
interpreter.execfile(filePath);
}
}

Python 代码:

# -*- coding: utf-8 -*-
import json
import sys
from famiover.model.model import Model
from famiover.util.excelsheet import ExcelSheet
from famiover.util.excelutil import ExcelUtil

def thrall(param):
eu = ExcelUtil('filename.xls')

dicts = {
'r1': json.loads(param)
}
model_key = 'thrall'
excelsheet = ExcelSheet(eu, 'Thrall项目异常列表', dicts, Model, model_key)
# 保存至excel
eu.excelutil_save()

if __name__ == '__main__':
thrall(sys.argv[1])
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: