Playing with IronPython

I've been dabbling with IronPython for the last few days, trying to host it and use it as a scripting engine. I have to say that I'm impressed. The hosting API is incredibly simple to use and Mike Stall's blog served as a handy reference.

One thing I wanted my scripts to do was to access private and internal members of types in the hosting application. I found that the command line python interpreter (ipy.exe) had a -X:PrivateBinding switch to allow access to private and internal members using the <type>_<type>__memberName convention (which seems to be the standard python name mangling for private members).

However, I couldn't find an easy way to do that from the hosting application. It was time to download the source code and figure out how the command line option got translated in code. It turned out to be pretty simple, there is a static class Options, which has properties for most of the command line options. From the hosting application, all you have to do is set the corresponding property before initializing the PythonEngine.

void Initialize()
{
Options.PrivateBinding = true;
pythonEngine = new PythonEngine();
}

 

Published Sat, May 12 2007 1:25 by Senthil
Filed under:

Leave a Comment

(required) 
(required) 
(optional)
(required)