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

Curt Hagenlocher curt at hagenlocher.org
Thu Mar 25 15:05:58 CET 2010


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/20100325/8dc80713/attachment.html>


More information about the Ironpython-users mailing list