A useful feature of the IPython Notebook is that you can set the server to broadcast so that others on your local network can see the server and your notebooks. This is especially nice as a teacher so that students can load your notebooks as you work, copy text out of them, and see them in their entirety instead of just what you have on screen. Here’s the outline of what to do, with detailed instructions below:
- Create an IPython profile with a password for the Notebook server.
- Figure out your IP address on the local network.
- Launch IPython in broadcast + read-only mode using your new profile.
- Have your students navigate to your Notebook server.
Read More »
Learning to program and learning the basics of control flow can be tricky business for novices. I wanted to make something that provided immediate, visual feedback to students as they practice things like
for loops and
if statements so they can see precisely what their code is (or isn’t) doing. So I wrote ipythonblocks.
The IPython Notebook makes it possible to display rich representations of Python objects using HTML (among other things). That allowed me to make a Python object whose representation in the Notebook is a colored table. Students can index into the table to change the color properties of individual table cells and then immediately display their changes.
ipythonblocks instructors can give coding problems like ‘turn every block in the third column red’ or ‘turn every blue block green’ and by displaying their blocks students can see right away whether their code is having the desired effect.
Check out the demo notebook to see ipythonblocks in action.
As a tool when teaching unit testing it would be great to have a way to run nose or pytest in an IPython Notebook. For example, a
%nosetests magic would do test collection in the Notebook namespace and do its usual run and reporting. Of course it’s always possible to write test functions and then just call them, but having a report that compiles everything in one place is nice. Plus it could look just like nosetests called from the command line.
Unfortunately for this idea these testing frameworks have for the most part been engineered for doing their test collection using the file system as the starting point. In a couple hours of fiddling I couldn’t figure out how to use either nose or pytest to do test collection in a notebook. I’m sure it could be done with enough hacking.
Just for kicks, though, I threw together a little IPython line magic that does its own limited test collection, running, and reporting. You can see it via nbviewer and grab it on GitHub. This magic only grabs functions that begin with “test” and the reporting doesn’t include tracebacks when there are failures or errors. But you do get the exceptions themselves.
(This whole experiment was inspired by a conversation on Twitter.)
Update: On the advice of @stefanvdwalt I put the
%runtests magic into a .py file so it can be installed via
Once that’s done you can run
to have it do its limited collection, running, and reporting as in this demo notebook.
Update 2: Someone has made this work with nose: https://github.com/taavi/ipython_nose!
I’m happy to announce that there is now a Firefox add-on with the same functionality as the Open in nbviewer Chrome extension and bookmarklet. It can be installed via the Mozilla Add-ons directory. It will add an nbviewer icon to Firefox’s toolbar that, when clicked, will attempt to open your current page in nbviewer.
The code is available on GitHub.
I got tired of pasting URLs into nbviewer so I made a Chrome extension that will try to load your current page via nbviewer.
For example, if you are at https://gist.github.com/3778422 you can click the “Open in nbviewer” extension button and it will load http://nbviewer.ipython.org/3778422/ in a new tab. It also works for URLs ending in
You can download the extension from the Chrome Web Store and see the code on GitHub.
I took the extension icon from the nbviewer favicon, so thanks to them for that! Thanks also for making something as awesome as nbviewer, it’s getting so I couldn’t live without it!
For a few months now I’ve been using the IPython Notebook as my primary teaching tool for Python topics. Within Software Carpentry we’re also switching over to using the Notebook for both in-person bootcamps and our online repository of material. Ethan White and I put together a post on this topic on the Software Carpentry blog and now Titus Brown has blogged with his own thoughts. We’ve put in a PyCon proposal for a panel on this topic in 2013.
The IPython developers have to be given a huge amount of credit for putting together the Notebook and the rest of IPython. The Notebook especially is quite a feat: a top notch research/engineering/teaching tool all in one. And they aren’t resting on their laurels, they have a ton of ideas in mind for the Notebook in the future, including a slide-show mode. I’m definitely looking forward to seeing what they’ve got!
As with many open source projects, the IPython developers struggle to find the time and funding to write their software. If any open source project is helping with your job or your research you can easily help by citing the software in your papers and in public on social media or blogs. This gives the developers more ammunition the next time they’re writing grants, so please make your support known!