Python和Java调用的方法操作是什么,代码怎样写
Admin 2022-06-20 群英技术资讯 659 次浏览
在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的序列化模块JSON与Pickle,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
在python中,我们经常会使用到字符串,它可以来表示文件的描述、硬件的标识等。字符串的使用可以方便我们编程的操作。我们在使用字符串的时候,也经常遇到分割这个词。你知道如何字符串分割字符串吗?今天小编就带大家认识一下python中分割字符串的explode() 函数。
通常需要对前端传递过来的参数进行校验,校验的方式有多种,本文主要介绍了Python中rapidjson参数校验实现,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要介绍了pycharm自动生成文件注释和函数注释的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
这篇文章主要和大家分享一下如何使用 mediapipe+opencv 制作桌上冰球的交互式小游戏,文中的示例代码讲解详细,感兴趣的小伙伴可以了解一下
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008