Embedding IronPython in C#

See embedding on the Voidspace site.

An example there, The IronPython Calculator and the Evaluator
works over a simple python expression evaluator called from a C# program.

public string calculate(string input)
{
    try
    {
        ScriptSource source =
            engine.CreateScriptSourceFromString(input,
                SourceCodeKind.Expression);

        object result = source.Execute(scope);
        return result.ToString();
    }
    catch (Exception ex)
    {
        return "Error";
    }
}

Leave a Comment