Hi Bob,<br><br>This blog post shall answer all your questions <a href="http://spellcoder.com/blogs/dodyg/archive/2008/04/15/12273.aspx">http://spellcoder.com/blogs/dodyg/archive/2008/04/15/12273.aspx</a><br><br>Dody G.<br>
<br><div class="gmail_quote">On Fri, Jun 27, 2008 at 5:51 PM, Bob Rosembob <<a href="mailto:brosembob@yahoo.com">brosembob@yahoo.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><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> </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> </div>
<div>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.</div>
<div> </div>
<div>I added references to my project to the following dlls:</div>
<div>- IronPython.dlll</div>
<div>- IronMath.dll</div>
<div> </div>
<div>In the code I'm using the following:</div>
<div><font size="2" color="#0000ff"><font size="2" color="#0000ff">
<p>using</p></font></font><font size="2"> IronPython.Runtime;</font><font size="2" color="#0000ff"><font size="2" color="#0000ff">
<p>using</p></font></font><font size="2"> IronPython.Runtime.Types;</font><font size="2" color="#0000ff"><font size="2" color="#0000ff">
<p>using</p></font></font><font size="2"> IronPython.Runtime.Operations;</font><font size="2" color="#0000ff"><font size="2" color="#0000ff">
<p>using</p></font></font><font size="2"> IronPython.Hosting;</font><font size="2" color="#0000ff"><font size="2" color="#0000ff">
<p>using</p></font></font><font size="2"> IronPython.Modules;</font>
<p><font size="2"></font> </p>
<p>Here is the code:</p>
<p> </p><font size="2">
<p></p></font><font size="2" color="#2b91af"><font size="2" color="#2b91af">PythonEngine</font></font><font size="2"> engine = </font><font size="2" color="#0000ff"><font size="2" color="#0000ff">new</font></font><font size="2"> </font><font size="2" color="#2b91af"><font size="2" color="#2b91af">PythonEngine</font></font><font size="2">();</font><font size="2" color="#008000"><font size="2" color="#008000"></font></font><font size="2">
<p></p></font><font size="2" color="#2b91af"><font size="2" color="#2b91af">EngineModule</font></font><font size="2"> module = engine.CreateModule(</font><font size="2" color="#a31515"><font size="2" color="#a31515">"Test"</font></font><font size="2">, </font><font size="2" color="#0000ff"><font size="2" color="#0000ff">true</font></font><font size="2">);
<p></p>
<p></p></font><font size="2" color="#0000ff"><font size="2" color="#0000ff">try</font></font><font size="2">
<p>{</p>
<p> engine.ExecuteFile(</p></font><font size="2" color="#a31515"><font size="2" color="#a31515">@"Test\Test.py"</font></font><font size="2">, module);
<p>}</p>
<p></p></font><font size="2" color="#0000ff"><font size="2" color="#0000ff">catch</font></font><font size="2"> (</font><font size="2" color="#2b91af"><font size="2" color="#2b91af">Exception</font></font><font size="2"> ex)
<p>{</p>
<p></p></font><font size="2" color="#2b91af"><font size="2" color="#2b91af"> Console</font></font><font size="2">.WriteLine(</font><font size="2" color="#a31515"><font size="2" color="#a31515">"Failed to execute <a href="http://test.py/" target="_blank">Test.py</a> file"</font></font><font size="2">);</font><font size="2">
<p></p></font><font size="2" color="#0000ff"><font size="2" color="#0000ff"> return</font></font><font size="2">;
<p>}</p>
<p> </p>
<p>//call the function????</p>
<p> </p>
<p><font size="3">So how do I do the call to the function?</font></p>
<p><font size="3"></font> </p>
<p><font size="3">Thanks for your help.</font></p>
<p><font size="3">Bob</font></p>
<p><font size="3"></font> </p></font></div></div><br></div></div></div><br>
</div><br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><a href="http://nomadlife.org">nomadlife.org</a><br>