Get last statement result in embedded IronPython v2

最后都变了- 提交于 2019-12-07 21:54:48

问题


This post in Mike Stall's blog states that

The last expression result is stored as the global variable "_", so you can retrieve it like so:

object o = m_python.GetVariable("_");

But currently in v2 scope has no such variable after executing, e.g.,

scriptEngine.CreateScriptSourceFromString("a=1+2;a+1", SourceCodeKind.Statements);

Is there any way to access result (a+1) without explicitly define variable?


回答1:


I suspect with IronPython 2 you need to use SourceCodeKind.Interactive.

I'll try it out later and see if this works.



来源:https://stackoverflow.com/questions/1966421/get-last-statement-result-in-embedded-ironpython-v2

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