This is very much worth doing: generate an assembly by precompiling a Python source file and then look at the result using Reflector.<br><br><div class="gmail_quote">On Wed, Jan 21, 2009 at 8:28 AM, Dody Gunawinata <span dir="ltr">&lt;<a href="mailto:empirebuilder@gmail.com">empirebuilder@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr">hmm..why would an IronPython assembly be different from a static language assembly? Wouldn&#39;t that negates the main point of the CLR?<div>
<br><div><br></div><div>Dody G.<br><br><div class="gmail_quote">On Wed, Jan 21, 2009 at 6:20 PM, Michael Foord <span dir="ltr">&lt;<a href="mailto:fuzzyman@voidspace.org.uk" target="_blank">fuzzyman@voidspace.org.uk</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Dody Gunawinata wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
string cmd = @&quot;from xxx import yy&quot;;<br>
<br>
eng.CreateScriptSourceFromString(cmd).Execute(--fill in default scope here--)<br>
</blockquote></div>
It will need to be:<br>
<br>
eng.CreateScriptSourceFromString(cmd, SourceCodeKind.Statements).Execute(scope)<br>
<br>
But I&#39;m pretty sure he will also need to use a different API for loading the assembly, assuming it is &nbsp;from compiled IronPython code rather than just an ordinary .NET assembly.<br>
<br>
Michael<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<br>
//then go one fetching the function<br>
<br></div><div>
On Wed, Jan 21, 2009 at 6:11 PM, Renaud Durand &lt;<a href="mailto:neraun@gmail.com" target="_blank">neraun@gmail.com</a> &lt;mailto:<a href="mailto:neraun@gmail.com" target="_blank">neraun@gmail.com</a>&gt;&gt; wrote:<br>


<br>
 &nbsp; &nbsp;That is the point. I don&#39;t want to do that from a file but from an<br>
 &nbsp; &nbsp;Assembly (dll).<br>
<br>
 &nbsp; &nbsp;2009/1/21 Dino Viehland &lt;<a href="mailto:dinov@microsoft.com" target="_blank">dinov@microsoft.com</a><br></div>
 &nbsp; &nbsp;&lt;mailto:<a href="mailto:dinov@microsoft.com" target="_blank">dinov@microsoft.com</a>&gt;&gt;<div><br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;You need to do:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; <br>
 &nbsp; &nbsp; &nbsp; &nbsp;eng.ExecuteFile(&#39;myfile.py&#39;, scope);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; <br>
 &nbsp; &nbsp; &nbsp; &nbsp;*From:* <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;[mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a><br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>&gt;] *On Behalf Of<br>
 &nbsp; &nbsp; &nbsp; &nbsp;*Renaud Durand<br>
 &nbsp; &nbsp; &nbsp; &nbsp;*Sent:* Wednesday, January 21, 2009 7:45 AM<br></div>
 &nbsp; &nbsp; &nbsp; &nbsp;*To:* <a href="mailto:dody@nomadlife.org" target="_blank">dody@nomadlife.org</a> &lt;mailto:<a href="mailto:dody@nomadlife.org" target="_blank">dody@nomadlife.org</a>&gt;;<div><br>
 &nbsp; &nbsp; &nbsp; &nbsp;Discussion of IronPython<br>
 &nbsp; &nbsp; &nbsp; &nbsp;*Subject:* Re: [IronPython] Calling a Python function<br>
 &nbsp; &nbsp; &nbsp; &nbsp;(compiled into an assembly) from C# using delegates.<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; <br>
 &nbsp; &nbsp; &nbsp; &nbsp;Ok, but how ?<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;2009/1/21 Dody Gunawinata &lt;<a href="mailto:empirebuilder@gmail.com" target="_blank">empirebuilder@gmail.com</a><br></div>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;mailto:<a href="mailto:empirebuilder@gmail.com" target="_blank">empirebuilder@gmail.com</a>&gt;&gt;<div><br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;I think you have to import the function - loading the assembly<br>
 &nbsp; &nbsp; &nbsp; &nbsp;alone is not enough.<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;On Wed, Jan 21, 2009 at 5:17 PM, Renaud Durand<br></div>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="http://renaud.durand.it" target="_blank">renaud.durand.it</a> &lt;<a href="http://renaud.durand.it" target="_blank">http://renaud.durand.it</a>&gt;@<a href="http://gmail.com" target="_blank">gmail.com</a><div>

<div></div><div><br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;<a href="http://gmail.com" target="_blank">http://gmail.com</a>&gt;&gt; wrote:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Hi again,<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;I&#39;m trying to call a python function from C#. I found out<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;through a tutorial how to do it from<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a Python source file but I would like to do it from a<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;compiled assembly. Some elements are missing.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;I think it is something like below but this does not work:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;eng = Python.CreateEngine()<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Assembly interpreter =<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Assembly.Load(&quot;interpreter&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;eng.runtime.LoadAssembly(interpreter);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ScriptScope scope = eng.CreateScope();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Get the interpretMapping function<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Func&lt;string, object&gt; interpretMapping;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;interpretMapping =<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;scope.GetVariable&lt;Func&lt;string, object&gt;&gt;(&quot;interpretMapping&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ObjectOperations ops = eng.Operations;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Get the interpItem returned by function.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;object item =<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;interpretMapping(&quot;649AC0165011B1E8F726AC54C911000000000000000000000000000000000000&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Get the display Method<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;object method = ops.GetMember(item, &quot;display&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ops.Call(method);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Thank you... Again :-)<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Renaud Durand<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EPITA Student<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_______________________________________________<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Users mailing list<br></div></div>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a> &lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<div>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<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>
<br>
<br>
<br></div>
 &nbsp; &nbsp; &nbsp; &nbsp;--  &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://nomadlife.org" target="_blank">nomadlife.org</a> &lt;<a href="http://nomadlife.org" target="_blank">http://nomadlife.org</a>&gt;<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;_______________________________________________<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Users mailing list<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a> &lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<div>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<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>
<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;--  &nbsp; &nbsp; &nbsp; &nbsp;Renaud Durand<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;_______________________________________________<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Users mailing list<br></div>
 &nbsp; &nbsp; &nbsp; &nbsp;<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a> &lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<div>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<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>
<br>
<br>
<br>
 &nbsp; &nbsp;--  &nbsp; &nbsp;Renaud Durand<br>
<br>
 &nbsp; &nbsp;_______________________________________________<br>
 &nbsp; &nbsp;Users mailing list<br></div>
 &nbsp; &nbsp;<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a> &lt;mailto:<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a>&gt;<div>
<br>
 &nbsp; &nbsp;<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>
<br>
<br>
<br>
-- <br>
</div><a href="http://nomadlife.org" target="_blank">nomadlife.org</a> &lt;<a href="http://nomadlife.org" target="_blank">http://nomadlife.org</a>&gt;<div><br>
<br>
------------------------------------------------------------------------<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">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>
 &nbsp;<br>
</div></blockquote>
<br>
</blockquote></div><br><br clear="all"><br>-- <br><a href="http://nomadlife.org" target="_blank">nomadlife.org</a><br><br>
</div></div></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>