Hi Curt, I noticed the Microsoft.Scripting.Hosting.ObjectOperations.Call(object, params object[])' is obsolete, you are correct, we should use Invoke instead. 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.
Thank you. Best Regards, Evan Wang ------------------------------ *From:* Evan WANG [mailto:wmr...@motorola.com] *Sent:* Friday, March 26, 2010 10:31 AM *To:* 'Discussion of IronPython' *Subject:* RE: [IronPython] Update from IronPython v1.0 to IronPython v2.6 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-boun...@lists.ironpython.com [mailto: users-boun...@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 <wmr...@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@lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > >
_______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com