从vb.net导入变量到python脚本

时间:2017-02-20 00:57:34

标签: python vb.net

我正在编写一个带有vb.net gui和python脚本的程序。 我已经创建了一个文本框来从vb.net gui获取用户输入,我想将输入带到python脚本进行计算(计算平均值)。 有没有人知道怎么做?

在vb.net中:

Public Class Form1
Dim var1 As String
Dim var2 As String
Dim Value As String

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    var1 = Val(TextBox2.Text)
    var2 = Val(TextBox3.Text)

    Dim proc As Process = New Process
    proc.StartInfo.FileName = "C:\Python27\python.exe" 'Default Python Installation
    proc.StartInfo.Arguments = "D:\Python\mean.py"
    proc.StartInfo.UseShellExecute = False 'required for redirect.
    proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden 'don't show commandprompt.
    proc.StartInfo.CreateNoWindow = True
    proc.StartInfo.RedirectStandardOutput = True 'captures output from commandprompt.
    proc.Start()
    AddHandler proc.OutputDataReceived, AddressOf proccess_OutputDataReceived
    proc.BeginOutputReadLine()
    proc.WaitForExit()

    TextBox1.Text = Value

End Sub
Public Sub proccess_OutputDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
    On Error Resume Next
    If e.Data = "" Then
    Else
        Value = e.Data
    End If
End Sub


End Class

在Python中:

def mean(values):
length = len(values)
total_sum = 0

for i in range(length):
    total_sum += values[i]

total_sum = sum(values)
average = total_sum/length
return average

x = [33, 33]
n = mean(x)
print(n)

0 个答案:

没有答案