A simple way to take Python code that already exists and bring it into a notebook is to use the %load
magic in a cell:
%load <filename>.p
Running this cell will load the contents of <filename>.py
into the current cell:
Running the cell again does not run the script – the point of using %load
was simply to include the script on the page, not execute it.
Using the %run
magic runs the script and inserts its output into the notebook as the output of that cell:
Tip
Using a notebook with tests
A notebook full of calls to test functions can be a convenient and attractive way to maintain a test suite and records of its results over time.
Of course, if the only thing a notebook did was to allow one to display the output of programs on a web page, it would be of limited usefulness. The real power of Jupyter comes into focus when working with individual cells.