[IronPython] Update from IronPython v1.0 to IronPython v2.6

Evan WANG wmrj76 at motorola.com
Fri Mar 26 03:30:43 CET 2010


   Hi Curt,
Thanks a lot for your instruction:)
Another option I tried yesterday like this:
            ScriptEngine engine = Python.CreateEngine();
            ScriptScope Scope = engine.CreateScope();
            ScriptSource source;
            source = engine.CreateScriptSourceFromFile("D:\\test.py");
            source.Execute(Scope);
            ObjectOperations operations = engine.Operations;
            object function = Scope.GetVariable("GetScriptInfo");
            int result = (int)operations.Call(function);

It works as well, but your option is better.

Best Regards,
Evan Wang

 ------------------------------
*From:* users-bounces at lists.ironpython.com [mailto:
users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher
*Sent:* Thursday, March 25, 2010 10:06 PM
*To:* Discussion of IronPython
*Subject:* Re: [IronPython] Update from IronPython v1.0 to IronPython v2.6

 One option is this:

            ScriptEngine engine = Python.CreateEngine();
            ScriptScope pyScope = engine.CreateScope();
            ScriptSource ss = engine.CreateScriptSourceFromFile("test.py");
            ss.Execute(pyScope);
            string address = engine.Operations.InvokeMember(pyScope,
"GetScriptInfo").ToString();


On Thu, Mar 25, 2010 at 1:27 AM, Evan WANG <wmrj76 at motorola.com> wrote:

>  Hi IronPython experts,
> I am a newcomers in the IronPython, I am working on update the IronPython
> engine in our c# project.
> After studied some days from all of your articles, I still have one
> question can't be fixed.
> In IronPython v1.0, we use the below code to call a function in the .py
> file
> this.pythonEngine = new PythonEngine();
> // Load the script
> this.pythonEngine.ExecuteFile(@filePath);
> string address;
> address = this.pythonEngine.Evaluate("GetScriptInfo").ToString();
>
> How can I implement this in the IronPython v2.6?
> I write some code in c# as below,
>
> ScriptEngine engine = Python.CreateEngine();
> ScriptScope pyScope = engine.CreateScope();
> ScriptSource ss;
> ss = engine.CreateScriptSourceFromFile("D:\\test.py");
> ss.Execute();
> ScriptSource execute the whole python file now, how can I call the specific
> function(for example, the GetScriptInfo() function)?
>
> test.py file:
> def GetScriptInfo ():
> sXML='<script>script info</script>'
> return sXML
>
> def GetBodyInfo ():
> sXML='<script>body info</script>'
> return sXML
>
> Thanks a lot!
>
> Best Regards,
> Evan Wang
>
>
> _______________________________________________
> 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/20100326/d43c4450/attachment.html>


More information about the Ironpython-users mailing list