<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta content="MSHTML 6.00.2900.3660" name="GENERATOR"></head>
<body>
<div dir="ltr" align="left"><font face="Tahoma" color="#0000ff" size="2"><span class="013542502-26032010"><font face="Tahoma" color="#0000ff" size="2">Hi
Curt,</font></span></font></div>
<div dir="ltr" align="left"><span class="013542502-26032010"><span class="215411810-26032010"><font color="#0000ff"><font face="Tahoma" size="2">I noticed
the Microsoft.Scripting.Hosting.ObjectOperations.Call(object, params object[])'
is obsolete, you are correct, we should use Invoke
instead.</font></font></span></span></div>
<div dir="ltr" align="left"><font face="Tahoma" color="#0000ff" size="2"><span class="013542502-26032010"><span class="215411810-26032010">Is there any api to
check whether specific function exists before call it in the .py file? because
if C# code call a nonexistent function in the .py file, it will occurs runtime
error.</span></span></font></div>
<div dir="ltr" align="left"><font face="Tahoma" color="#0000ff" size="2"><span class="013542502-26032010"><span class="215411810-26032010"></span></span></font> </div>
<div dir="ltr" align="left"><font face="Tahoma" color="#0000ff" size="2"><span class="013542502-26032010"><span class="215411810-26032010">Thank
you.</span></span></font></div>
<div dir="ltr" align="left"><font face="Tahoma" color="#0000ff" size="2"><span class="013542502-26032010"><span class="215411810-26032010"></span></span></font> </div>
<div dir="ltr" align="left"><font face="Tahoma" color="#0000ff" size="2"><span class="013542502-26032010"><span class="215411810-26032010">Best
Regards,</span></span></font></div>
<div dir="ltr" align="left"><font face="Tahoma" color="#0000ff" size="2"><span class="013542502-26032010"><span class="215411810-26032010">Evan
Wang</span></span></font></div>
<div dir="ltr" align="left"><font face="Tahoma" color="#0000ff" size="2"></font> </div>
<div class="OutlookMessageHeader" lang="en-us" dir="ltr" align="left">
<hr tabindex="-1">
<font face="Tahoma" size="2"><b>From:</b> Evan WANG [mailto:<a href="mailto:wmrj76@motorola.com">wmrj76@motorola.com</a>]
<br><b>Sent:</b> Friday, March 26, 2010 10:31 AM<br><b>To:</b> 'Discussion of
IronPython'<br><b>Subject:</b> RE: [IronPython] Update from IronPython v1.0 to
IronPython v2.6<br></font><br></div>
<div></div>
<div dir="ltr" align="left"><span class="013542502-26032010"><font face="Tahoma" color="#0000ff" size="2">Hi Curt,</font></span></div>
<div dir="ltr" align="left"><span class="013542502-26032010"><font face="Tahoma" color="#0000ff" size="2">Thanks a lot for your instruction:)</font></span></div>
<div dir="ltr" align="left"><span class="013542502-26032010"><font face="Tahoma" color="#0000ff" size="2">Another option I tried yesterday like
this:</font></span></div>
<div dir="ltr" align="left"><span class="013542502-26032010"><font face="Tahoma" color="#0000ff" size="2"><font color="#808000">
ScriptEngine engine =
Python.CreateEngine();<br>
ScriptScope Scope =
engine.CreateScope();<br>
ScriptSource
source;<br>
source =
engine.CreateScriptSourceFromFile("D:\\test.py");<br>
source.Execute(Scope);<br>
ObjectOperations operations =
engine.Operations;<br>
object function =
Scope.GetVariable("GetScriptInfo");<br>
int result =
(int)operations.Call(function);</font><br> </font></span></div>
<div dir="ltr" align="left"><span class="013542502-26032010"><font face="Tahoma" color="#0000ff" size="2">It works as well, but your option is
better.</font></span></div>
<div dir="ltr" align="left"><span class="013542502-26032010"><font face="Tahoma" color="#0000ff" size="2"></font></span> </div>
<div dir="ltr" align="left"><span class="013542502-26032010"><font face="Tahoma" color="#0000ff" size="2">Best Regards,</font></span></div>
<div dir="ltr" align="left"><span class="013542502-26032010"><font face="Tahoma" color="#0000ff" size="2">Evan Wang</font></span></div><br>
<div class="OutlookMessageHeader" lang="en-us" dir="ltr" align="left">
<hr tabindex="-1">
<font face="Tahoma" size="2"><b>From:</b> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>
[mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Curt
Hagenlocher<br><b>Sent:</b> Thursday, March 25, 2010 10:06 PM<br><b>To:</b>
Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] Update from
IronPython v1.0 to IronPython v2.6<br></font><br></div>
<div></div>
<div>One option is this:</div>
<div> </div>
<div>
ScriptEngine engine =
Python.CreateEngine();<br>
ScriptScope pyScope =
engine.CreateScope();<br>
ScriptSource ss =
engine.CreateScriptSourceFromFile("test.py");<br>
ss.Execute(pyScope);<br> string
address = engine.Operations.InvokeMember(pyScope,
"GetScriptInfo").ToString();<br><br> </div>
<div class="gmail_quote">On Thu, Mar 25, 2010 at 1:27 AM, Evan WANG <span dir="ltr"><<a href="mailto:wmrj76@motorola.com">wmrj76@motorola.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div><span><font face="Tahoma" size="2">Hi IronPython experts,</font></span></div>
<div><span><font face="Tahoma" size="2">I am a newcomers in the IronPython, I am
working on update the IronPython engine in our c# project.</font></span></div>
<div><span><font face="Tahoma" size="2">After studied some days from all of your
articles, I still have one question can't be fixed.</font></span></div>
<div><span><font face="Tahoma" size="2">In IronPython v1.0, we use the below code
to call a function in the .py file</font></span></div>
<div><span></span><span><font face="Tahoma" color="#0000ff" size="2">this.pythonEngine = new PythonEngine();</font></span></div>
<div><span><font face="Tahoma" color="#0000ff" size="2">// Load the
script<br>this.pythonEngine.ExecuteFile(@filePath);
</font></span></div>
<div><span><font face="Tahoma" color="#0000ff" size="2">string
address;</font></span></div>
<div><span><font face="Tahoma" color="#0000ff" size="2">address =
this.pythonEngine.Evaluate("GetScriptInfo").ToString();</font></span></div>
<div><span><font face="Tahoma" size="2"></font></span> </div>
<div><span><font face="Tahoma" size="2">How can I implement this in the IronPython
v2.6?</font></span></div>
<div><span><font face="Tahoma" size="2">I write some code in c# as
below,</font></span></div>
<div><span><font face="Tahoma" size="2"></font></span> </div>
<div><span><font face="Tahoma" color="#808000" size="2">ScriptEngine engine =
Python.CreateEngine();<br>ScriptScope pyScope =
engine.CreateScope();<br>ScriptSource ss;<br>ss =
engine.CreateScriptSourceFromFile("D:\\test.py");<br>ss.Execute();</font></span></div>
<div><span><font face="Tahoma" size="2">ScriptSource execute the whole python file
now, how can I call the specific function(for example, the GetScriptInfo()
function)?</font></span></div>
<div><span><font face="Tahoma" size="2"></font></span> </div>
<div><span><font face="Tahoma" size="2">test.py file:<br><font color="#800000">def
GetScriptInfo ():<br>sXML='<script>script info</script>'
<br>return sXML<br><br>def GetBodyInfo ():<br>sXML='<script>body
info</script>' <br>return sXML</font></font></span></div>
<div><span><font face="Tahoma" size="2"></font></span> </div>
<div><span><font face="Tahoma" size="2">Thanks a lot!</font></span></div>
<div><span><font face="Tahoma" size="2"></font></span> </div>
<div><span><font face="Tahoma" size="2">Best Regards,</font></span></div>
<div><span><font face="Tahoma" size="2">Evan Wang </font></span></div>
<div><span><font face="Tahoma" size="2"></font></span> </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></body></html>