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);

Comments

Popular posts from this blog

ionic2 cordova build android - Unable resolve gradle 2.2.3

OpenCover code coverage for .Net Core

Using Custom DLL with IronPython / Scripts