6 Stimmen

Wie setze ich __name__ auf '__main__', wenn ich IronPython hosted verwende?

Bei der Verwendung von IronPython hosted the __name__ spezielle Variable kehrt zurück als <module> anstelle von __main__ . Ich habe hier eine Diskussion gefunden: http://lists.ironpython.com/pipermail/users-ironpython.com/2006-August/003274.html . Aber ich weiß nicht, wie ich sie auf meinen Code anwenden soll:

public static void RunPythonFile(string filename)
{
    // This is the Key to making sure that Visual Studio can debug
    // the Python script. This way you can attach to 3dsMax.exe
    // and catch exceptions that occur right at the correct location 
    // in the Python script. 
    var options = new Dictionary<string, object>();
    options["Debug"] = true;

    // Create an instance of the Python run-time
    var runtime = Python.CreateRuntime(options);

    // Retrive the Python scripting engine 
    var engine = Python.GetEngine(runtime);

    // Get the directory of the file 
    var dir = Path.GetDirectoryName(filename);                       

    // Make sure that the local paths are available.
    var paths = engine.GetSearchPaths();                
    paths.Add(dir);
    engine.SetSearchPaths(paths);

    // Execute the file
    engine.ExecuteFile(filename);
}

CodeJaeger.com

CodeJaeger ist eine Gemeinschaft für Programmierer, die täglich Hilfe erhalten..
Wir haben viele Inhalte, und Sie können auch Ihre eigenen Fragen stellen oder die Fragen anderer Leute lösen.

Powered by:

X