Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic Jython script examples?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Xiaobian to share with you the basic Jython script examples, I believe most people do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

After installing the Jython development environment, you can try writing *** Jython scripts. Suppose you want to query system properties, such as OS platform. A script to do this is shown in Listing 1.

Listing 1. Jython Script Sample

#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

Note: In Python, the #sign is a line comment identifier.

After you enter the code in Listing 1 into the Jython interpreter interactive console, the console displays the results. You can also save this snippet as a Jython script file with the.py extension. If the file path is/root/sample.py, run this script in wsadmin using the command wsadmin -lang Jython-f /root/sample.py. The results are shown in Listing 2.

Listing 2. Jython Script Sample Run Results: Display OS Name

The os property "os.name" is assigned with the value: "Linux";

If a script calls functions or class methods of other Jython modules, use the execfile function to load Jython scripts from other Jython script files. Listing 3 shows an example:

listing 3. Jython Script Example: Calling External Functions

execfile('/root/Sample.py') prop = querySysProperty os.name print 'the os property \"os.name\" is assigned with the value:', prop The above is "What are the basic Jython script examples" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report