获取最后一条语句的结果在嵌入式IronPython的V2 [英] Get last statement result in embedded IronPython v2

查看:95
本文介绍了获取最后一条语句的结果在嵌入式IronPython的V2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章在迈克失速的博客指出




最后一个表达式的结果保存为全局变量_,这样你就可以检索它像这样:

 对象o = m_python.GetVariable(_); 




但目前在V2范围内具有执行之后没有这样的变量,例如:

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

有什么办法来访问结果(A + 1)没有明确定义变量?


解决方案

我的IronPython 2,您需要使用SourceCodeKind.Interactive怀疑。



我会稍后再试一下,看看这是否正常工作。


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?

解决方案

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

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

这篇关于获取最后一条语句的结果在嵌入式IronPython的V2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆