问题
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