Python和Java调用的方法操作是什么,代码怎样写
Admin 2022-06-20 群英技术资讯 513 次浏览
在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进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要给大家介绍了关于Python自定义模块创建与使用的相关资料,文中还给大家分享了python打包用户自定义模块的方法,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
所谓定时器,是指间隔特定时间执行特定任务的机制。几乎所有的编程语言,都有定时器的实现。这篇文章主要介绍的是通过Python实现的定时器,感兴趣的可以跟随小编学习一下
这篇文章主要介绍了通过Python实现一个简单的电影售票系统,文中的示例代码对我们学习Python有一定的帮助,感兴趣的小伙伴可以跟随小编一起学习一下
如何用python实现自动翻译工具?很多朋友应该都有遇到过,在查找资料的时候,一些资料都是有大量英文的,那么这对于英文不是很好地朋友来说,阅读就比较困难,因此自动翻译攻击就显得很重要,对这这篇文章就给大家来分析Python 实现自动化翻译和替换的脚本,感兴趣的朋友就接着看吧。
我们可以用python里面的time模块mktime方法将转为unix时间戳,mktime函数只能接受相应时间的元祖序列。在此之前需要先将输入的时间转为元组序列:如果输入的时间为指定格式的,则可以用strptime()函数根据指定的格式把一个时间字符串解析为时间元组,time.strptime(string[,format])例如:time.strptime('2017-11-181
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008