[IronPython] Calling a Python function (compiled into an assembly) from C# using delegates.

Renaud Durand renaud.durand.it at gmail.com
Wed Jan 21 16:17:40 CET 2009


Hi again,

I'm trying to call a python function from C#. I found out through a tutorial
how to do it from
a Python source file but I would like to do it from a compiled assembly.
Some elements are missing.
I think it is something like below but this does not work:

            eng = Python.CreateEngine()
            Assembly interpreter = Assembly.Load("interpreter");
            eng.runtime.LoadAssembly(interpreter);

            ScriptScope scope = eng.CreateScope();

            //Get the interpretMapping function
            Func<string, object> interpretMapping;
            interpretMapping = scope.GetVariable<Func<string,
object>>("interpretMapping");
            ObjectOperations ops = eng.Operations;

            //Get the interpItem returned by function.
            object item =
interpretMapping("649AC0165011B1E8F726AC54C911000000000000000000000000000000000000");
            //Get the display Method
            object method = ops.GetMember(item, "display");
            ops.Call(method);

Thank you... Again :-)

-- 
Renaud Durand
EPITA Student
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20090121/e21f208d/attachment.html>


More information about the Ironpython-users mailing list