5

In IPython one can get previous outputs and inputs via Out[n] and In[n] variables. Is it possible to use the contents of a Markdown notebook cell and use it in python.

I would like to write some text in a Markdown cell

This is Markdown I would like to manipulate with.

Then I would like to use this text in the next python cell

md_cell = ???
print md_cell.replace("Markdown", "Markup")
... # do stuff, write it to a file, be happy

to do something with it.

mrcin
  • 116
  • 1
  • 5
  • Not easily, no - the idea is that the kernel doesn't know about the notebook document. People have more often asked for a way to include Python variable values in markdown cells, but that has other complexities. – Thomas K Mar 11 '14 at 18:11
  • I can allways load the notebook file itself with `json.load(open('test.ipynb','r'))` and dig out the right cell. How can I find out the number of current prompt? – mrcin Mar 12 '14 at 23:30
  • You can, but you have to hardcode the filename. In the kernel, you can get the current execution count (prompt number) with `get_ipython().execution_count`. – Thomas K Mar 13 '14 at 20:14

0 Answers0