IPython Notebook previous cell content

2019-07-17 16:38发布

问题:

Is it possible in an IPython-Notebook cell to get the previous (above) cell content ?

I can see previous output with %capture magic function but I don't find how to get the previous cell content.

回答1:

I didn't find how to get the previous content cell in a cell.

But I found another solution, creating a custom magic notebook function to capture the cell content and work with that.



回答2:

You can get content of the last executed cell with:

In[len(In)-2]


回答3:

%recall jupyter_notebook_cell_number

Should give you the code that was last executed in indicated particular notebook cell, jupyter_notebook_cell_number