I'm creating a module whose intended audience uses Jupyter NoteBook. Part of this involves reading the contents of the cell it is being run from.

Thanks to this Stack answer, It can be achieved by running:

In[len(In) - 1]

How could this be run in an ordinary Python file?

I have already tried using subprocess through subprocess.call(["ipython", "-c", cmd]), yet this creates a seperate instance of iPython, which as a result is empty.

Saving it in an .ipy file has also been tried. This is troublesome though since it is hard to package and import.

I am grateful for any help.

0 Answers