问题描述
我是vb.net的新手.我试图从vb.net调用python函数,但收到"Invoke"不是"Microsoft.Scripting.Hosting.ObjectOperations"的成员的错误
I am new with vb.net. I am trying to call python functions from vb.net but getting error that 'Invoke' is not a member of '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
' name of the method thaT NEEDS TO INVOKED AND GET THE RETURN VALUE. Can anyone please recommend me better way to make this work? I have already seen this link :http://msmvps.com/blogs/theproblemsolver/archive/2008/08/14/calling-ironpython-functions-from-net.aspx
先谢谢您.
推荐答案
类似以下的方法应该起作用:
Something like the following should work:
Sub Main(ByVal args() As String)
Dim pyRT As ScriptRuntime = Python.CreateRuntime()
Dim workingObj As Object = pyRT.UseFile("working.py")
workingObj.methodName()
End Sub
这篇关于从vb.net运行Python函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!