[IronPython] Embedded IronPython 2.6 Module Name

jhoward at drawloop.com jhoward at drawloop.com
Tue Nov 17 23:02:00 CET 2009

I realize I'm replying rather late, but I just got to trying this
again.  This is something that really should be simple.  Anytime a
module is run from the ScriptEngine directly, I would expect the
behavior to be running as "__main__" just as if I was running it from
the command line using "ipy" or "python".  Unfortunately, trying to
create a module directly doesn't work as far as naming the module.
Using the following code:

            PythonModule pm = new PythonModule();
            ScriptEngine se = Python.CreateEngine();
            PythonContext pc = (PythonContext)
            pc.PublishModule("__main__", pm);
            ScriptScope ss = HostingHelpers.CreateScriptScope(se, new
            ss.SetVariable("__name__", "__main__");
            ss.SetVariable("__doc__", "");

doesn't work.  There's no way to directly get the Scope from the
PythonModule when working this way, as it's been marked as internal.
Looking through the debugger, the _scope variable that actually holds
the scope on the PythonModule object is null.  I believe the old
CreateModule way of doing this would have worked, but there's no way
to that I've found to do this now.

At this point, I'm really not sure how 2.6 is being marked as a
release candidate.

On an unrelated note, I could, in IronPython 1.1.2 do the following

            _pyEngine.Execute("python code", _pyEngine.DefaultModule,

where "args" is a Dictionary<string, object> and have those arguments
passed in to a function call or the like.  Is there any way to do this
using the new hosting engine?

Thanks again.

On Nov 6, 2:18 pm, Curt Hagenlocher <c... at hagenlocher.org> wrote:
> It looks like you can just create the PythonModule directly now -- it's a
> public class with a public constructor.
> On Thu, Nov 5, 2009 at 12:14 PM, Jonathan Howard <jhow... at drawloop.com>wrote:
> > Thanks for the help, Curt.  Perhaps it's a problem with the latest, RC?
> >  There is no "CreateModule" function on the PythonContext object.
> > ~Jonathan
> > _______________________________________________
> > Users mailing list
> > Us... at lists.ironpython.com
> >http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> Us... at lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com

More information about the Ironpython-users mailing list