<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV>Hi there,</DIV>
<DIV>&nbsp;</DIV>
<DIV>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. </DIV>
<DIV>&nbsp;</DIV>
<DIV>I need to call Python function from C# to get&nbsp;a value. When&nbsp;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.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I added references to my project to the following dlls:</DIV>
<DIV>- IronPython.dlll</DIV>
<DIV>- IronMath.dll</DIV>
<DIV>&nbsp;</DIV>
<DIV>In the code I'm using the following:</DIV>
<DIV><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> IronPython.Runtime;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> IronPython.Runtime.Types;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> IronPython.Runtime.Operations;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> IronPython.Hosting;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> IronPython.Modules;</FONT></P>
<P><FONT size=2></FONT>&nbsp;</P>
<P>Here is the code:</P>
<P>&nbsp;</P><FONT size=2>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>PythonEngine</FONT></FONT><FONT size=2> engine = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT><FONT size=2> </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>PythonEngine</FONT></FONT><FONT size=2>();</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2></P></FONT></FONT><FONT size=2>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>EngineModule</FONT></FONT><FONT size=2> module = engine.CreateModule(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"Test"</FONT></FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>true</FONT></FONT><FONT size=2>);</P>
<P></P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>try</P></FONT></FONT><FONT size=2>
<P>{</P>
<P>&nbsp;&nbsp;&nbsp; engine.ExecuteFile(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>@"Test\Test.py"</FONT></FONT><FONT size=2>, module);</P>
<P>}</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>catch</FONT></FONT><FONT size=2> (</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Exception</FONT></FONT><FONT size=2> ex)</P>
<P>{</P>
<P></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>&nbsp;&nbsp;&nbsp; Console</FONT></FONT><FONT size=2>.WriteLine(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"Failed to execute <A href="http://test.py/" target=_blank>Test.py</A> file"</FONT></FONT><FONT size=2>);</P></FONT><FONT size=2>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; return</FONT></FONT><FONT size=2>;</P>
<P>}</P>
<P>&nbsp;</P>
<P>//call the function????</P>
<P>&nbsp;</P>
<P><FONT size=3>So how do I do the call to&nbsp;the function?</FONT></P>
<P><FONT size=3></FONT>&nbsp;</P>
<P><FONT size=3>Thanks for your help.</FONT></P>
<P><FONT size=3>Bob</FONT></P>
<P><FONT size=3></FONT>&nbsp;</P></FONT></DIV></DIV><BR></DIV></DIV></div><br>



      </body></html>