5

我是 vb.net 的新手。我正在尝试从 vb.net 调用 python 函数,但出现“Invoke”不是“Microsoft.Scripting.Hosting.ObjectOperations”成员的错误

Imports Microsoft.Scripting
Imports Microsoft.Scripting.Hosting
Imports IronPython.Hosting
Sub Main
 Dim engine As ScriptEngine
        Dim scope As ScriptScope
        Dim i As Integer


        engine = Python.CreateEngine()
        scope = engine.ExecuteFile("C:\Working.py")
 Dim v = engine.Operations.Invoke(scope.GetVariable(methodName))

' 需要调用并获取返回值的方法的名称。谁能推荐我更好的方法来完成这项工作?我已经看过这个链接: http: //msmvps.com/blogs/theproblemsolver/archive/2008/08/14/calling-ironpython-functions-from-net.aspx

先感谢您。

4

1 回答 1

1

像下面这样的东西应该可以工作:

  Sub Main(ByVal args() As String) 
    Dim pyRT As ScriptRuntime = Python.CreateRuntime() 
    Dim workingObj As Object = pyRT.UseFile("working.py")   
    workingObj.methodName() 
  End Sub
于 2014-08-05T18:16:46.177 回答