[IronPython] Call Python function from C#...

Curt Hagenlocher curt at hagenlocher.org
Fri Jun 27 17:21:41 CEST 2008


Your reference to IronMath.dll indicates that you're using IronPython 1.x.
You can find a relevant hosting example at
http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET

The hosting interface for IronPython 2 is radically different; an equivalent
example can be found at
http://www.ironpython.info/index.php/Hosting_IronPython_2.


On Fri, Jun 27, 2008 at 7:51 AM, Bob Rosembob <brosembob at yahoo.com> wrote:

>    Hi there,
>
> I apologize if this is a duplicate message. I sent this message last night
> but don't see it posted. Perhaps I did something wrong and message got lost.
>
>
> I need to call Python function from C# to get a value. When I call the
> script it executes and calculates some value, then I need to call some
> function to get the result. How do I do that? I have the following snippet
> of code that seems to execute the script, but I don't know and can't find on
> line, how to call a function and get value back.
>
> I added references to my project to the following dlls:
> - IronPython.dlll
> - IronMath.dll
>
> In the code I'm using the following:
>
> using
> IronPython.Runtime;
>
> using
> IronPython.Runtime.Types;
>
> using
> IronPython.Runtime.Operations;
>
> using
> IronPython.Hosting;
>
> using
> IronPython.Modules;
>
>
>
> Here is the code:
>
>
>
> PythonEngine engine = new PythonEngine();
>
> EngineModule module = engine.CreateModule("Test", true);
>
> try
>
> {
>
>     engine.ExecuteFile(
> @"Test\Test.py", module);
>
> }
>
> catch (Exception ex)
>
> {
>
>     Console.WriteLine("Failed to execute Test.py <http://test.py/> file");
>
>     return;
>
> }
>
>
>
> //call the function????
>
>
>
> So how do I do the call to the function?
>
>
>
> Thanks for your help.
>
> Bob
>
>
>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080627/ed68927f/attachment.html>


More information about the Ironpython-users mailing list