1
VBによって呼び出され、増分された整数を返すためのIronPythonを取得できません。 返される値は、IronPythonに渡される値と同じです。VB.NETでVB変数をインクリメントするためにIronPythonを呼び出そうとする
変数123をIronPythonに渡し、IronPythonに変数を10個追加してVBでそれを取得させたいと思っています。 しかし、それはまだ123に戻ります。
Imports System
Imports System.IO
Imports Microsoft.Scripting
Imports Microsoft.Scripting.Hosting
Imports IronPython.Hosting
Public Class Form1
Private Sub Button_GO_Click(sender As Object, e As EventArgs) Handles Button_GO.Click
' HELLO WORLD...
' bring up an IronPython runtime
dim engine = Python.CreateEngine()
dim scope = engine.CreateScope()
' create a source tree from code '
dim source = engine.CreateScriptSourceFromString("print 'hello from python'")
' run the script in the IronPython runtime'
source.Execute(scope)
' MODIFY VARIABLE: BUG: returns 1 instead of 11'
engine = Python.CreateEngine()
scope = engine.CreateScope()
' create a Python variable "i" with the value 1'
scope.SetVariable("i", 1)
' this script will simply add 1 to it '
source = engine.CreateScriptSourceFromString("i += 10")
' pull the value back out of IronPython and display it:'
dim response = scope.GetVariable("i")
debug.print( response)
End Sub
End Class