# python_script.pydefhello():return"Hello from Python!"
1.
2.
3.
3. 编写VB6代码
在VB6中,可以使用Shell函数来调用Python脚本,并获取返回结果。
Private Sub Command1_Click()
Dim objShell As Object
Dim objScriptExec As Object
Dim strPythonPath As String
Dim strScriptPath As String
Dim strResult As String
Set objShell = CreateObject("WScript.Shell")
strPythonPath = "C:\Python\python.exe"
strScriptPath = "C:\path\to\python_script.py"
' 使用Shell函数执行Python脚本
Set objScriptExec = objShell.Exec(strPythonPath & " " & strScriptPath)
' 读取Python脚本的输出
strResult = objScriptExec.StdOut.ReadAll
MsgBox strResult
End Sub