如何编写一个知道单元格输入数字的单元格魔术?

use*_*974 2 python ipython jupyter-notebook

有没有办法编写一个知道单元格输入编号的单元格魔术?我所说的“输入数字”是指?单元格In[?]前缀中的。乍一看,似乎IPython.core.magic.cell_magic只知道细胞内容——还有什么办法可以超越这一点吗?

use*_*974 6

execution_count此信息由 shell的当前实例提供IPython,可以通过以下方式获取get_ipython

print(get_ipython().execution_count)
Run Code Online (Sandbox Code Playgroud)