You can also find a blog post and a self containing sample on what you are trying to do here - http://blogs.msdn.com/seshadripv/archive/2008/06/30/how-to-invoke-a-python-function-from-c-using-the-dlr-hosting-api.aspx
Thanks sesh -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tomas Matousek Sent: Friday, August 22, 2008 1:42 PM To: Discussion of IronPython Subject: Re: [IronPython] How to call a function passing parameters You can do: var runtime = ScriptRuntime.Create(); var scope = runtime.CreateScope("python"); scope.Execute(@" def test(a): return a "); var test = scope.GetVariable<Func<string, string>>("test"); Console.WriteLine(test(my_a)); Tomas -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fernando Correia Sent: Friday, August 22, 2008 1:32 PM To: Discussion of IronPython Subject: [IronPython] How to call a function passing parameters Please help me to call an IronPython function passing parameters from a C# method. Let's say I have a ScriptEngine and also a ScriptScope. In the scope I have a Python function like this: def test(a): return a Then in some C# method I have something like: string my_a = "A"; How can I call that function passing to it my_a in place of the "a" parameter? I want to pass the actual object, not just its value, so I can pass complex objects and manipulate them in IronPython. Without passing parameters, I can already do this: var functionCall = string.Format("{0}()", FunctionName); ScriptSource function = engine.CreateScriptSourceFromString(functionCall, SourceCodeKind.Expression); function.Execute(scope); Thanks for any help. _______________________________________________ Users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
