开发者

Automatically echo the result of an assignment statement in IPython [duplicate]

开发者 https://www.devze.com 2023-01-27 01:33 出处:网络
This question already has answers here: IPython magic print variables on assignment (2 answers) Closed 4 years ago开发者_StackOverflow.
This question already has answers here: IPython magic print variables on assignment (2 answers) Closed 4 years ago开发者_StackOverflow.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消