The easiest way to import a file as a module is with ScriptRuntime.UseFile.
On Mon, Jul 12, 2010 at 2:51 PM, Danny Fernandez <fernandez....@gmail.com>wrote: > Hi I am planning on using IronPython 2.6.1 .NET 2.0 in a embedded in my C# > app. I am playing with able > to call python functions from C#. I had a question about how do you call > other functions from modules > that were imported. Here is a simple example > > moduleA.py has the following > > import moduleB > > def myFunA(): > return 1 > > > moduleB.py has the following > > def myFunB(): > return 2 > > This is what I have in my sample C# program. > > ScriptSource source = _engine.CreateScriptSourceFromFile("moduleA); > CompiledCode compiledCode = source.Compile(); > ScriptScope scope = _engine.CreateScope(); > compiledCode.Execute(scope); > > > I can get access to myFunA straight forward with > > Func<int> funcA = scope.GetVariable<Func<int>>("myFunA"); > > > How do I access other functions from other modules in this simple case > myFunB from the import moduleB? > I was able to with the following but I am not sure if this is correct way > or if there are better way > > PythonModule stuff = scope.GetVariable<PythonModule>("moduleB"); > Func<int> funcB= _engine.Operations.GetMember<Func<int>>(stuff, "myFunB"); > > > Thanks > > Danny > > _______________________________________________ > 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