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

How to write a cell magic that knows the input number of the cell?

有没有办法编写一个知道单元格输入数字的单元格魔术? "input number" 是指单元格 In[?] 前缀中的 ?。乍一看,IPython.core.magic.cell_magic 似乎只知道单元格内容——有什么办法可以超越它吗?

此信息由 IPython shell 当前实例的 execution_count 提供,可通过 get_ipython:

获得
print(get_ipython().execution_count)