我使用的软件有一个基于VBA / Winwrap Basic的编程接口。我想使用一些来自Python的机器学习库,但我不确定如何有效地构建它。
该软件是一个动态仿真程序。每隔几个时间步,我就想用Pyhton库中的新数据更新(训练)一个人工神经网络(ANN)。我可以看到调用脚本是可能的(就像在How to call python script on excel vba?中一样)。因为我必须每隔几次调用一次脚本,所以我不确定如何处理ANN对象。实现这一点的最佳方式是什么?
发布于 2018-11-13 09:48:22
如果我理解正确的话,您希望调用Python脚本并传递参数,然后处理返回的数据对象?如果您使用Windows并具有VBA脚本环境,那么您也许可以使用WSH (windows脚本主机)对象来运行脚本。首先声明对象
Dim wsh As New IWshRuntimeLibrary.WshShell 'early binding
Dim wsh As Object
Set wsh = CreateObject("Wscript.Shell") ' late binding并在对象上使用Run()方法,将对象和参数作为字符串传递。在本例中,我调用powershell并传递scriptfile (run.ps1)作为参数。我只是调用了这个方法,但没有从脚本中获得返回对象。
res = wsh.Run("powershell path\run.ps1", WindowStyle:=False, WaitOnReturn:=True)
If res = 0 Then
Call MsgBox("script ran successfully")
Else
Call MsgBox("script ran unsuccessfully")
End If另一方面,在本例中,我使用Exec方法获取json形式的返回数据
res = wsh.Exec("powershell path\run.ps1").StdOut.ReadAll()
Debug.Print res ' return data:
returnObject:
{
title: 'theTitle',
value: 'the value',
status: 'status'
}run.ps1基本上返回一个字符串:
return "returnObject:
{
title: 'theTitle',
value: 'the value',
status: 'status'
}"编辑:调用python脚本文件的在powershell中使用python或py
res = wsh.Exec("python path\pythonfile.py").StdOut.ReadAll()https://stackoverflow.com/questions/52927708
复制相似问题