<div>I'm not sure if there's a simpler way -- here's what I did a few months back when I needed to publish something via __main__:</div>
<div> </div>
<div>pythonContext = HostingHelpers.GetLanguageContext(self._engine)</div>
<div>module = pythonContext.CreateModule()<br>pythonContext.PublishModule('__main__', module)<br>scope = HostingHelpers.CreateScriptScope(self._engine, module.Scope)<br>scope.SetVariable('__name__', '__main__')<br>
scope.SetVariable('__doc__', '')<br><br>HostingHelpers is a class in the DLR hosting interfaces. From C#, you'd need to explicitly cast the LanguageContext to a PythonContext.</div>
<div> </div>
<div>After this, you would run your Python code within the "scope" ScriptScope.<br></div>
<div class="gmail_quote">On Thu, Nov 5, 2009 at 10:57 AM, Jonathan Howard <span dir="ltr"><<a href="mailto:jhoward@drawloop.com">jhoward@drawloop.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Hi,
<div><br></div>
<div>We're trying to upgrade to IronPython 2.6 and are having a number of issues with it. The biggest issue is there doesn't appear to be a way to name the module that runs when you embed your code. We're using the Hosting API to create and run code within C#. The code runs, but we have other modules that are supposed to pull globals from the __main__ module. This worked in 1.1 by setting the DefaultModule on the PythonEngine instance. There doesn't seem to be a way to do this anymore.</div>
<div><br></div>
<div>Any help would be appreciated.</div>
<div><br></div><font color="#888888">
<div>~Jonathan</div></font><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>