[IronPython] PythonEngine.SetVariable not in 1.0 RC1

Mark Rees mark.john.rees at gmail.com
Fri Jul 28 05:08:07 CEST 2006

Yes the hosting api has changed. It was documented in the beta9
release announcement:


But to paraphrase:

One of the most significant changes is the final updates to the
hosting API.  The hosting APIs have removed the concept of a
ModuleScope and replaced it with a normal dictionary.  Here is a
sample of how you can use the new hosting APIs:

       EngineOptions engineOptions = new EngineOptions();
       engineOptions.ShowClrExceptions = true; // do some customization
       PythonEngine engine = new PythonEngine(engineOptions);
       Dictionary<string, object> globals = new Dictionary<string, object>();
       globals["x"] = 1; // set a global variable
       EngineModule module = engine.CreateModule("MyModule", globals, true);
       module.Globals["y"] = 2; // set another global variable
       Dictionary<string, object> locals = new Dictionary<string, object>();
       locals["z"] = 3; // set a local variable
       engine.Compile("result = x+y+z").Execute(module, locals);
       Console.WriteLine(engine.EvaluateAs<int>("result", module, locals));

We've also added new PythonEngine.CreateMethod and
PythonEngine.CreateLambda methods.  These allow you to bind either a
set of Python statements or a single expression to a delegate.  The
parameters of the delegate are exposed to the Python code, and the
delegate can be re-bound to different modules at runtime providing a
quick way to provide different inputs to your cached Python code.

On 7/28/06, Jean-Michel.Perraud at csiro.au <Jean-Michel.Perraud at csiro.au> wrote:
> Hi,
> I am looking at RC1 and noticed that the PythonEngine.SetVariable method is not present anymore. Has is been deprecated and if so what is the new equivalent to expose .NET objects as variables via a hosted engine?
> The last version I used to compile against was Beta6.
> Cheers,
> J-M
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

More information about the Ironpython-users mailing list