[IronPython] IP 2 Hosting

Michael Foord fuzzyman at voidspace.org.uk
Sat Mar 29 18:00:52 CET 2008

Hello guys,

I'm trying to do some simple examples of hosting with IronPython 2. Boy 
you made things more complicated than IronPython 1. :-)

Unfortunately the DLR hosting spec document is out of date. I have a 
couple of questions (but will keep exploring).

The simplest use case is just to evaluate an expression and return a result.

The hosting spec document mention 'ScriptRuntime.Execute(text)'. This 
may or may not be the right way to evaluate an expression, but in any 
case it has been removed.

An alternative is:

    engine = PythonEngine.CurrentEngine # a ScriptEngine
    unit = engine.CreateSourceUnitFromString(code, id)
    result = unit.Execute()

Which is straightforward enough, however I can't see a way to set 
TrueDivision using this technique.  (What is the 'id' by the way?)

I can see that TrueDivision is a setting on 
IronPython.Runtime.ModuleOptions and IronPython.Runtime.PythonModule. 
Can I set this on the engine somehow?

All the alternative seem to lead down a rabbit warren of 'create this 
object - which requires this object - which you construct from another 
object - which...'. I don't know which path to follow down the rabbit 


Any suggestions to save me from madness?


More information about the Ironpython-users mailing list