IPython magic print variables on assignment

后端 未结 2 1643
Happy的楠姐
Happy的楠姐 2020-12-17 04:55

Is there a parameter in IPython to print the variables each time I assign them ?

Currently:

In [1]: a = 5

In [2]: a
Out[2]: 5

In [3]: b = a + 1

In         


        
2条回答
  •  猫巷女王i
    2020-12-17 05:41

    As of IPython 6.2, this exists, but the command to turn it on is really long:

    %config InteractiveShell.ast_node_interactivity='last_expr_or_assign'
    

    You can set it in your ipython_config.py, if you want it to be on by default:

    c = get_config()
    c.InteractiveShell.ast_node_interactivity = 'last_expr_or_assign'
    

    It only triggers when the assignment target is a simple name; assignments like arr[i] = val or obj.attr = 3 will not auto-print.

提交回复
热议问题