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?
Asked
Active
Viewed 399 times
2

user209974
- 1,737
- 2
- 15
- 31
1 Answers
6
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)

user209974
- 1,737
- 2
- 15
- 31
-
make sure to delete all cells that do not have any content – Gregor von Laszewski Aug 05 '22 at 15:54