[IronPython] C# replacement wrapper for ipy.exe
Doug Blank
doug.blank at gmail.com
Tue Mar 22 20:06:30 CET 2011
I'm using the following C# code as a replacement for "ipy.exe
myscript.py". One reason for doing this is that this can be run in the
background on Unix/Mac OSX under Mono, whereas ipy.exe can not. I
don't know if there are other reasons, or if there are speed
differences.
However, my FullFrames isn't working under IronPython 2.6 beta 2. Some
questions:
1) Is this a good replacement for ipy.exe? Anything that I should do
different or add? Any other -X flags I should consider?
2) Does FullFrames work under IronPython 2.6 beta 2 under Mono? If so,
is there something I am doing wrong?
Thanks for any ideas,
-Doug
using System;
using IronPython.Hosting;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using System.Diagnostics;
public class MyProject {
static void Main(string[] args) {
ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup();
LanguageSetup language = Python.CreateLanguageSetup(null);
language.Options["FullFrames"] = true;
scriptRuntimeSetup.LanguageSetups.Add(language);
ScriptRuntime runtime = new
Microsoft.Scripting.Hosting.ScriptRuntime(scriptRuntimeSetup);
ScriptScope scope = runtime.CreateScope();
ScriptEngine engine = runtime.GetEngine("python");
ScriptSource source = engine.CreateScriptSourceFromFile("myscript.py");
source.Compile();
try {
source.Execute(scope);
} catch (IronPython.Runtime.Exceptions.SystemExitException e) {
// exit
}
}
}
More information about the Ironpython-users
mailing list