安装 Jython开发环境后,您可以尝试编写***个 Jython脚本。假定您需要查询系统属性,例如 OS 平台。清单 1 中显示了实现此操作的脚本。
成都创新互联公司专业为企业提供富蕴网站建设、富蕴做网站、富蕴网站设计、富蕴网站制作等企业网站建设、网页设计与制作、富蕴企业网站模板建站服务,10余年富蕴做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
清单 1. Jython脚本示例
- #import java.lang.System.class
- from java.lang import System
- def querySysProperty(propertyName):
- prop = System.getProperty(propertyName)
- return prop
- prop = querySysProperty('os.name')
- print 'the os property \"os.name\" is assigned with the value: ', prop
注意:在 Python 中,# 符号是行注释标识符。
在您将清单 1 中的代码输入 Jython解释器交互控制台后,控制台上会显示结果。也可以将此代码片段另存为具有 .py 扩展名的 Jython脚本文件。如果文件路径是 /root/sample.py,则在 wsadmin 中使用命令 wsadmin -lang Jython–f /root/sample.py 运行此脚本。清单 2 中显示了结果。
清单 2. Jython脚本示例运行结果:显示 OS 名称
- The os property "os.name" is assigned with the value: "Linux";
如果某个脚本调用其他 Jython模块的函数或类方法,则使用 execfile 函数加载来自其他 Jython脚本文件的 Jython脚本。清单 3 显示了一个示例:
清单 3. Jython脚本示例:调用外部函数
- execfile('/root/Sample.py')
- prop = querySysProperty('os.name')
- print 'the os property \"os.name\" is assigned with the value:', prop
当前题目:几个基础的Jython脚本示例
文章网址:http://www.shufengxianlan.com/qtweb/news18/407518.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联