run Python functions from vb.net

别说谁变了你拦得住时间么 提交于 2019-12-22 06:49:24

问题


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))

' 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

Thank you in advance.


回答1:


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


来源:https://stackoverflow.com/questions/24022818/run-python-functions-from-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!