想从groovy脚本执行python代码吗

2024-10-01 22:35:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个需要从groovy脚本调用/执行python脚本的情况。我怎么能做到呢?在

下面是我用groovy编写的执行python脚本的代码

def task = ["/Users/amiteshshukla/Documents/Work/PythonTest/Test.py"]
def executeTask = task.execute()
executeTask.waitForOrKill(1000)
println (executeTask.text)

这是我试图通过groovy执行的python代码示例

^{pr2}$

当我执行groovy脚本时,我希望得到以下输出: “****我的名字是阿米蒂什****”

但是,我得到了这个输出。在

task = ["/Users/amiteshshukla/Documents/Work/PythonTest/Test.py"]
executeTask = task.execute()
executeTask.waitForOrKill(1000)
println(text)

Tags: 代码pytest脚本taskexecutedefusers
1条回答
网友
1楼 · 发布于 2024-10-01 22:35:08

在python脚本中添加shebang行。这样操作系统就知道它需要通过python解释器调用脚本。在

#!/usr/bin/env python

class Test:

    def callMyName(self):
        print("****My name is amitesh****")


t = Test()
t.callMyName()

相关问题 更多 >

    热门问题