Passing Parameter from C# to IronPython
Code in Python
/////////////////////////////////////////////////
def calc(a, b):
return a+b
print calc(x,y)
/////////////////////////////////////////////////
C# code to pass parameter into the IronPython code
ScriptScope ScriptingScope = null;
ScriptEngine ScriptingHostingEngine = null;
ScriptingHostingEngine = IronPython.Hosting.Python.CreateRuntime().GetEngine("python");
ScriptSource ScriptRequest = ScriptingHostingEngine.CreateScriptSourceFromFile("c:\\del\\expression\\ScriptingTest\\ConsoleApplication1\\Program.py");
ScriptingScope = ScriptingHostingEngine.Runtime.CreateScope();
ScriptingHostingEngine.SetVariable(ScriptingScope, "x", 100);
ScriptingHostingEngine.SetVariable(ScriptingScope, "y", 200);
ScriptRequest.Execute(ScriptingScope);
/////////////////////////////////////////////////
def calc(a, b):
return a+b
print calc(x,y)
/////////////////////////////////////////////////
C# code to pass parameter into the IronPython code
ScriptScope ScriptingScope = null;
ScriptEngine ScriptingHostingEngine = null;
ScriptingHostingEngine = IronPython.Hosting.Python.CreateRuntime().GetEngine("python");
ScriptSource ScriptRequest = ScriptingHostingEngine.CreateScriptSourceFromFile("c:\\del\\expression\\ScriptingTest\\ConsoleApplication1\\Program.py");
ScriptingScope = ScriptingHostingEngine.Runtime.CreateScope();
ScriptingHostingEngine.SetVariable(ScriptingScope, "x", 100);
ScriptingHostingEngine.SetVariable(ScriptingScope, "y", 200);
ScriptRequest.Execute(ScriptingScope);
Comments