Powershell 调用带有参数的 ironpython 函数

Powershell calls ironpython function with arguments

使用下面的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"));

您可以像这样将它们作为 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);