如何编写一个知道细胞输入编号的细胞魔术? [英] How to write a cell magic that knows the input number of the cell?
本文介绍了如何编写一个知道细胞输入编号的细胞魔术?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以知道单元格的输入编号,从而编写出一个单元魔术? 输入数字"是指单元格In[?]
前缀中的?
.乍一看,IPython.core.magic.cell_magic
似乎只知道单元格的内容-除此之外还有什么办法吗?
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?
推荐答案
此信息由IPython
shell的当前实例的execution_count
提供,可以通过get_ipython
获得:
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)
这篇关于如何编写一个知道细胞输入编号的细胞魔术?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文