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__:
pythonContext = HostingHelpers.GetLanguageContext(self._engine) module = pythonContext.CreateModule() pythonContext.PublishModule('__main__', module) scope = HostingHelpers.CreateScriptScope(self._engine, module.Scope) scope.SetVariable('__name__', '__main__') scope.SetVariable('__doc__', '') HostingHelpers is a class in the DLR hosting interfaces. From C#, you'd need to explicitly cast the LanguageContext to a PythonContext. After this, you would run your Python code within the "scope" ScriptScope. On Thu, Nov 5, 2009 at 10:57 AM, Jonathan Howard <jhow...@drawloop.com>wrote: > Hi, > > 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. > > Any help would be appreciated. > > ~Jonathan > > _______________________________________________ > 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