<div>For this scenario, yes, you'd need to parse "moduleB.myFunB" into a module name and function name, then pull moduleB out of the scope for moduleA, pull myFunB out of the scope for moduleB and then execute it.</div>
<div> </div>
<div>If you expect to get a function, Operations.InvokeMember is cleaner than doing Operations.GetMember and casting to a delegate type.</div>
<div> </div>
<div>If you want to execute an arbitrary snippet of code against the scope of moduleA, (ie "moduleB.myFunB()") you can just compile the code and execute it by using ScriptEngine.Execute(string, ScriptScope).<br>
<br></div>
<div class="gmail_quote">On Wed, Jul 14, 2010 at 5:48 AM, Danny Fernandez <span dir="ltr"><<a href="mailto:fernandez.dan@gmail.com">fernandez.dan@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>Hi Curt,</div>
<div> </div>
<div> In my C# test app just simple demo app for me to learn more. I have a textbox that I enter the function name I want to execute with my entry point using "moduleA.py". If I type myFunA and enter I execute this pretty straightforward I think. If I type moduleB.myFunB in the textbox and execute. I am not sure how best to access functions that were imported. <br>
<br>If I use the ScriptRuntime.UseFile </div>
<div> </div>
<div>ScriptScope scope = engine.RunTime.UseFile("ModuleA");</div>
<div> </div>
<div>What would be the best way to get access to myFunB defined in ModuleB?</div>
<div> </div>
<div>If this doesn't make sense it's all good but its weird how things make sense in your own head. </div>
<div> </div>
<div>Thanks</div>
<div> </div><font color="#888888">
<div>Danny<br><br> </div></font>
<div>
<div></div>
<div class="h5">
<div class="gmail_quote">On Tue, Jul 13, 2010 at 9:59 AM, Curt Hagenlocher <span dir="ltr"><<a href="mailto:curt@hagenlocher.org" target="_blank">curt@hagenlocher.org</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">The easiest way to import a file as a module is with ScriptRuntime.UseFile.<br><br>
<div class="gmail_quote">
<div>
<div></div>
<div>On Mon, Jul 12, 2010 at 2:51 PM, Danny Fernandez <span dir="ltr"><<a href="mailto:fernandez.dan@gmail.com" target="_blank">fernandez.dan@gmail.com</a>></span> wrote:<br></div></div>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>
<div></div>
<div>
<div>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 <br>to call python functions from C#. I had a question about how do you call other functions from modules<br>that were imported. Here is a simple example<br>
<br>moduleA.py has the following</div>
<p>import moduleB</p>
<p>def myFunA():<br> return 1</p>
<p><br>moduleB.py has the following</p>
<p>def myFunB():<br> return 2</p>
<div><br>This is what I have in my sample C# program.<br><br>ScriptSource source = _engine.CreateScriptSourceFromFile("moduleA);<br>CompiledCode compiledCode = source.Compile();<br>ScriptScope scope = _engine.CreateScope();<br>
compiledCode.Execute(scope);</div>
<p><br>I can get access to myFunA straight forward with</p>
<p>Func<int> funcA = scope.GetVariable<Func<int>>("myFunA");</p>
<p><br>How do I access other functions from other modules in this simple case myFunB from the import moduleB?</p>
<div>I was able to with the following but I am not sure if this is correct way or if there are better way<br><br>PythonModule stuff = scope.GetVariable<PythonModule>("moduleB");<br>Func<int> funcB= _engine.Operations.GetMember<Func<int>>(stuff, "myFunB");</div>
<div><br><br>Thanks</div>
<p>Danny</p><br></div></div>
<div>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com" target="_blank">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></div></blockquote></div><br><br>_______________________________________________<br>Users mailing list<br><a href="mailto:Users@lists.ironpython.com" target="_blank">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></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>