Burned all my notebooks
June 14, 2017 at 12:23 AM by Dr. Drang
People who do data analysis in Python really like the Jupyter Notebook environment. It’s interactive and can mix text, code, and graphics in the same document—reminiscent of the Mathematica environment I used back in the late 80s and early 90s, but with a web browser as the front end instead of a native app. I decided last year to give it a good workout, using it in several projects over the course of six months or more. Ultimately, I decided it wasn’t for me, and I switched back to an editor/terminal system that sounds more primitive but is more efficient for the way I work.
The problem with Jupyter Notebook is twofold:
- Working in a notebook is clumsy. A text field on a web page simply can’t compare to a full-featured text editor. And I was continually forgetting to switch modes between code and Markdown. As for the interactivity, exploratory work often involves rerunning commands with slightly different parameters, and I found copying and editing notebook cells far less efficient than using a Readline-capable terminal.
- The output isn’t useful in my work. I can’t give a Jupyter notebook file to my clients, I have to write a report, so the notebook format doesn’t save me any time. Worse, I typically have to provide paper (or PDF) copies of all my background work, and the cell-based formatting of most notebooks makes them very long with weird page breaks.
So although the notebook metaphor looks nice, it’s harder to write than a regular script, isn’t as efficient as a standard REPL, and generates a file that isn’t helpful in communicating with my clients.
So I’ve gone back to writing regular scripts in BBEdit and doing the interactive work in a Terminal running Jupyter in console mode. This is invoked within Terminal by the command
jupyter console
Because I’m lazy and use this command so often, I have this alias in my .bashrc
file so I can just type jc
:
alias jc='jupyter console'
The two magic commands of Jupyter console (which it inherited from IPython) that allow me to switch back and forth between writing in BBEdit and exploring in Terminal are:
%run <filename>
for loading the script file into the console session and allowing me to then enter new lines into the REPL to test the code and check results.%reset -f
for deleting all definitions from the console environment, both those created by%run
and those created interactively (the-f
forces the reset so I don’t get asked for confirmation). This command is usually a precursor to another%run
with a newly edited version of the script.
Because %reset -f
doesn’t delete the command history, I can quickly reinvoke both of these commands as needed during script development and exploration.
Even better, I can work almost the same way on my iPad. With Split View, I can have a text editor (like Textastic) in one pane working on a script file synced through Dropbox and Prompt in the other pane connected to my iMac at work via SSH.
I’m sure notebooks work perfectly for lots of people, but I ain’t got time for that now.