网站制作优化济南seo推广教学
主要使用两个函数,一个是run函数,一个runResults函数,两者区别如下:
两个函数均接受一个字符串作为输入,默认输出类型也为字符串。字符串表示要执行的Python代码。
pyCom.run("import plotter");
Attempt attempt=pyCom.run("import plotter");
traceln("Import was successful?%s",attempt.isSuccessful());
数据类型的分配:
pyCom.run("value=3.14"); #分配浮点型数据
pyCom.run("text= 'hello'"); #分配字符型数据
在使用runResults返回时,默认是字符型。
String feedbackStr = pyCom.runResults("3+5").getFeedback(); #分配浮点型数据
int feedbackInt = pyCom.run("3+5").getFeedback(int.class); #分配整数型数据
# 或者如下形式
int feedbackInt = pyCom.runResults(int.class,"3+5");
转为JSON格式数据。
String json = "{\"nVehicles\":5,\"ncapacity\":120}";
ManufacturingCenter mfc = pyCom.fromAgentJson(json,ManufacturingCenter.class);
本地Python文件导入时,将Python文件放置在同模型文件相同的文件夹下。
另外,Python代码可以以字符串形式传入Pycom.run的参数中,执行Python程序。
调用参数时,可以使用占位符,得到参数。