我正在創建一個項目,我在IronPython中創建一個IronPython編譯器,依賴於IronPython, 但是我在調試腳本時可能會遇到一些問題,並且可以使用斷點?你能給我一些幫助嗎?謝謝。我的代碼有:https://github.com/heyxEvget/IronPython-Debugger]如何使用IronPython逐步調試腳本?
public ScriptEngine GetEngine()
{
if (_engine != null)
return _engine;
_engine = Python.CreateEngine();
_engine.Runtime.IO.SetOutput(_stream, Encoding.UTF8);
_engine.Runtime.IO.SetErrorOutput(_stream, Encoding.UTF8);
string path = Environment.CurrentDirectory;
string ironPythonLibPath = string.Format(@"{0}\IronPythonLib.zip", path);
var paths = _engine.GetSearchPaths() as List<string> ?? new List<string>();
paths.Add(path);
paths.Add(ironPythonLibPath);
path = Environment.GetEnvironmentVariable("IRONPYTHONPATH");
if (!string.IsNullOrEmpty(path))
{
var pathStrings = path.Split(';');
paths.AddRange(pathStrings.Where(p => p.Length > 0));
}
_engine.SetSearchPaths(paths.ToArray());
return _engine;
}
private void GetPythonVarsInfo(ScriptScope scope)
{
_varList.Clear();
var items = scope.GetItems();
foreach (var item in items)
{
_varList.Add(new VarValue
{
VarName = item.Key,
Value = item.Value
});
}
valueListView.ItemsSource = _varList;
}
private void OnExecuteButtonClick(object sender, ItemClickEventArgs e)
{
string outPutString = string.Empty;
outPutString = "*************************************" +
"Excute Date: " + DateTime.Now.ToLocalTime().ToString(CultureInfo.InvariantCulture);
ExeceutePython(document, outPutString);
TabControl.SelectedIndex = 2;
}
private void ExeceutePython(EditorDocument document, string outPutString)
{
ScriptEngine engine = GetEngine();
string script = document.Text;
ScriptSource source = engine.CreateScriptSourceFromString(script);
ScriptScope scope = _engine.CreateScope();
try
{
source.Compile();
OutputTextBox.AppendText(outPutString + Environment.NewLine);
var result = source.Execute(scope);
if (result != null)
{
OutputTextBox.AppendText(engine.Operations.Format(result));
}
OutputTextBox.AppendText(Environment.NewLine);
GetPythonVarsInfo(scope);
}
catch (Exception ex)
{
var eo = engine.GetService<ExceptionOperations>();
var eoString = eo.FormatException(ex);
OutputTextBox.AppendText(eoString);
return;
}
}
你應該提供您的問題更多的信息,包括一些代碼,你已經嘗試了什麼。但據我所知,你不能在c#中調試腳本。 mAybe以下鏈接也將有所幫助:http://stackoverflow.com/questions/31369279/is-there-any-way-to-debug-python-code-embedded-in-c-sharp-with-visual-studio-和 – HimBromBeere
嗨,我剛剛開始學習IronPython及其幫助文檔,並且我想創建一個Python編譯器白色的C#代碼依賴於Ironpython引擎,我還沒發現Python引擎有任何方法來調試腳本。所以我要求有人在那裏尋求幫助。 – Heyx
我使用syntaxeditor作爲我的編輯控件,通過Actiprosoftware.so創建我只需要編譯後面用於調試的代碼。 – Heyx