使用下面的powershell代码,如何使用参数调用ironpython的函数,应将参数写入哪里?
[reflection.assembly]::LoadFrom("C:\Program Files\IronPython 2.7\IronPython.dll")
$py = [ironpython.hosting.python]::CreateEngine()
$pyv = $py.CreateScope()
$pyc = $py.CreateScriptSourceFromString(
"
def fun(name):
print("Welcome", name)
def fun2(x,y,z):
res = x - y - z
return res
");
$pyc.Execute($pyv)
$py.Operations.Invoke($pyv.GetVariable("fun"));
$py.Operations.Invoke($pyv.GetVariable("fun2"));
答案 0 :(得分:0)
您可以像这样将它们作为Operations.Invoke
的第二个参数传入:
[reflection.assembly]::LoadFrom("C:\Program Files\IronPython 2.7\IronPython.dll")
$py = [ironpython.hosting.python]::CreateEngine()
$pyv = $py.CreateScope()
$pyc = $py.CreateScriptSourceFromString(
@"
def fun(name):
print("Welcome", name)
def fun2(x,y,z):
res = x - y - z
return res
"@
);
$one = "yo"
$two = 1, 2, 3
$pyc.Execute($pyv)
$py.Operations.Invoke($pyv.GetVariable("fun"), $one);
$py.Operations.Invoke($pyv.GetVariable("fun2"), $two);