ipython:自动回显赋值语句的结果? [英] ipython: automatically echo result of assignment statement?

查看:86
本文介绍了ipython:自动回显赋值语句的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让iPython自动回显赋值语句的结果?

Is there a way to make iPython automatically echo the result of an assignment statement?

例如,在MATLAB中,结束没有分号的赋值语句会打印赋值的结果,并且在语句末尾加一个分号会抑制任何输出。 / p>

For example, in MATLAB, ending an assignment statement without a semicolon prints the result of the assignment, and putting a semicolon at the end of the statement suppresses any output.

>> b=1+2

b =

     3

>> b=1+2;
>> 

我希望能够在iPython中做类似的事情。但是,如果我想查看分配结果,目前我必须使用两个单独的语句:

I want to be able to do something similar in iPython. However, currently I have to use two separate statements if I want to see the assignment result:

In [32]: b=1+2

In [33]: b
Out[33]: 3


推荐答案

赋值纯粹是Python中的一个语句,所以你必须编译代码,遍历AST,找到赋值,然后打印变量的<$ c运行后$ c> repr()。

Assignment is purely a statement in Python, so you'd have to compile the code, walk the AST, find the assignment, and then print the variable's repr() after running it.

这篇关于ipython:自动回显赋值语句的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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