自动回显 IPython 中赋值语句的结果
有没有办法让 IPython 自动回显赋值语句的结果?
例如,在 MATLAB 中,不以分号结束赋值语句会打印赋值结果,并在语句末尾添加分号会抑制任何输出。
>> b=1+2
b =
3
>> b=1+2;
>>
我希望能够在 IPython 中做类似的事情。但是,目前如果我想查看赋值结果,我必须使用两个单独的语句:
In [32]: b=1+2
In [33]: b
Out[33]: 3
Is there a way to make IPython automatically echo the result of an assignment statement?
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;
>>
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
赋值纯粹是 Python 中的一条语句,因此您必须编译代码,遍历 AST,找到赋值,然后在运行后打印变量的
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.