Can VS's IronPython Interactive window work with variables in .py file invoked from C# via CreateScriptSourceFromFile call?

可紊 提交于 2020-03-26 04:36:22

问题


There is a scenario where a C# process loads up and executes a .py file (code below) that is supported for debugging by PTVS in VS.

private void button_Click(object sender, RoutedEventArgs e)
{
        var engine = IronPython.Hosting.Python.CreateEngine(new Dictionary<string, object> { { "Debug", ScriptingRuntimeHelpers.True } });
        var source = engine.CreateScriptSourceFromFile("..\\..\\script.py");
        dynamic result = source.Execute();
} 

This is described in Is there any way to debug Python code embedded in C# with Visual Studio and PTVS? as well as how to use IronPython to debug the Script step by step?

However, I've been wondering - is there a way to make Visual Studio's IronPython Interactive window work with variables in the python script (i.e. make it connect to same debugging session)?

e.g. If I startup Python Interactive window from scratch, I can get import clr and get VS completions on clr. (e.g. AddReference, etc). But neither when writing script.py nor when inspecting variables in script.py in watch window do I get as rich completions as in the Interactive window - which is why I'd like to experiment with Python Interactive window, however it never seems to connect to my debugging session (so it does not pick up the variable 'foo'), as it clearly starts up its own Python process - but perhaps there is a trick to make it happen?

来源:https://stackoverflow.com/questions/59449916/can-vss-ironpython-interactive-window-work-with-variables-in-py-file-invoked-f

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!