简体   繁体   English

如何使用Python运行Jython脚本

[英]How can I run a Jython script with Python

I am programming in Python(2.7), processing a bunch of data. 我正在用Python(2.7)进行编程,处理大量数据。 And I've got a software, what I have to use, and I want to start it automatically, and fill it up with data. 我有一个软件,需要使用什么软件,我想自动启动它,并用数据填充它。

The problem is, that I cant open it with Python, because it has API only for Jython. 问题是,我无法使用Python打开它,因为它仅具有Jython的API。

My question is, that how could I run a Jython script from a Python code(actually I am working on a standalone software)? 我的问题是,我怎么能从Python代码运行Jython脚本(实际上我正在开发独立软件)? Is it even possible? 可能吗?

If it is, could you please give me a short example? 如果是,请给我一个简短的例子吗? How to install Jython and how to run a file from python? 如何安装Jython以及如何从python运行文件?

You can simply use Jython to run everything. 您只需使用Jython即可运行所有内容。

Having my_script.py and jython_script.py edit my_script.py by adding import jython_script and adding call jython_script.some_function() . my_script.pyjython_script.py通过添加import jython_script并添加调用jython_script.some_function() jython_script.py编辑my_script.py

# my_script.py
import jython_script

def my_function_using_some_function_from_jython_script():
    ...
    jython_script.some_function()
    ...

Then simply call: 然后只需调用:

jython my_script.py

I assume you do not use modules that work only with CPython. 我假设您不使用仅适用于CPython的模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM