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

这一生的挚爱 提交于 2020-05-09 17:09:42

问题


Is there a way to write a cell magic that knows the input number of the cell? By "input number" I mean the ? in the cell's In[?] prefix. At first glance, it seems that IPython.core.magic.cell_magic only knows about the cell content -- it there any way to go beyond that?


回答1:


This information is provided by the execution_count of the current instance of the IPython shell, that can be obtained with get_ipython:

print(get_ipython().execution_count)


来源:https://stackoverflow.com/questions/60694633/how-to-write-a-cell-magic-that-knows-the-input-number-of-the-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!