且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Groovy脚本调用python类的方法

更新时间:2022-05-14 07:16:26

在终端中执行脚本时,您使用了字符串文字"param1","param2" ,而不是未定义的变量 param1,param2 .由于您已经使用了单引号和双引号,因此应在反引号旁使用双引号:

When you executed the script in the terminal, you used the string literals "param1", "param2" , not the undefined variables param1, param2. Since you have already used both single and double quotes, you should escape the double quotes with a backslash:

def cmd = "cd /path && python -c 'import Myclass; Myclass.method(\"param1\", \"param2\")'"

或者,只需使用三引号:

or, just use the triple quotes:

def cmd = '''cd /path && python -c 'import Myclass; Myclass.method("param1", "param2")' '''