Ausführen einer bestimmten Python-Funktion in C# mit IronPython

Bisher habe ich eine einfache Klasse, die wraps ein python-engine (IronPython) für meinen Gebrauch. Obwohl der code sieht so groß, es ist wirklich einfach, also ich kopiere es hier zu mehr klar mit meinem Problem.

Hier der code:

public class PythonInstance
{
    ScriptEngine engine;
    ScriptScope scope;
    ScriptSource source;

    public PythonInstance()
    {
        engine = Python.CreateEngine();
        scope = engine.CreateScope();
    }

    public void LoadCode(string code)
    {
        source = engine.CreateScriptSourceFromString(code, Microsoft.Scripting.SourceCodeKind.Statements);
        source.Compile();
    }

    public void SetVariable(string key, dynamic variable)
    {
        scope.SetVariable(key, variable);
    }

    public void RunCode()
    {
        source.Execute(scope);
    }

    public void CallFunction(string function)
    {
        //?????? no idea what to call here
    }

}

So, es funktioniert Super, aber nur mir erlaubt, führen Sie alle python-Skript auf einmal... aber was ich möchte zu tun ist, um der Lage sein, bestimmte Funktionen innerhalb einer pythos Skript.

So, meine Frage: Wie rufe ich eine bestimmte Funktion in der geladenen Skript?

Ich versuche zu finden, einige Informationen oder tutorials, aber konnte leider nichts finden.

InformationsquelleAutor NewProger | 2013-01-03
Schreibe einen Kommentar