[IronPython] How to Use site.py

Jesse Wiles jwiles at webworks.com
Sun Sep 3 20:17:01 CEST 2006


Is there an example of how to sourcing site.py when instantiating a 
PythonEngine from a C# assembly can be used to add the standard CPython 
Lib path to that instances sys.path?  Here's my C# method:

    private void ExecutePythonFile(string ParamScriptPath, 
                                   IDictionary<string, object> ParamGlobals)
      EngineOptions VarEngineOptions = new EngineOptions();
      VarEngineOptions.ClrDebuggingEnabled = true;
      VarEngineOptions.ExceptionDetail = true;
      VarEngineOptions.ShowClrExceptions = true;

      PythonEngine VarEngine = new PythonEngine(VarEngineOptions);


      string VarScriptsDir = Path.GetDirectoryName(ParamScriptPath);

      ParamGlobals["ParameterScriptsDirectory"] = this.mScriptsDirectory;
      ParamGlobals["ParameterConfigurationPath"] = Path.Combine(VarScriptsDir, "configuration.xml");

      EngineModule VarMainModule = VarEngine.CreateModule("__main__", ParamGlobals, true);

      VarEngine.ExecuteFile(ParamScriptPath, VarMainModule);

and here's the contents of my Lib/site.py:

import sys

Jesse Wiles

More information about the Ironpython-users mailing list