In most cases you will open the underlying code in your editor or IDE, modify it, test it in another session (or with unit tests), then optionally install changes locally. You then start to work with the data and soon realize that you need slightly different data from one of the functions in one of the modules you control, so you need to add another parameter to query data differently. Futhermore, let’s say in your notebook you load all the data into memory and this takes a full 5 minutes. This will be a very typical use case for many users. You get the data by executing functions in modules you import at the beginning of your session, and those modules are Python code that you control. Let’s say you have a Jupyter notebook that you’ve created and are enhancing, and you require data from several sources. What this means is that modules loaded into your session can be modified (outside your session), and the changes will be detected and reloaded without you having to restart your session. The %autoreload magic changes the Python session so that modules are automatically reloaded in that session before entering the execution of code typed at the IPython prompt (or the Jupyter notebook cell). For this article, we’ll look at just one of the line magics, the %autoreload magic. ![]() A line magic consumes one line, whereas a cell magic consumes the lines below the magic, allowing for more input. A line magic is prefixed with one %, a cell magic is prefixed with two, %%. Magics are just special functions that you can call in your IPython or Jupyter session. One thing to note is that I’m talking about Python here, not other languages running in a Jupyter notebook. Jupyter notebooks, like IPython, support most of the same magics, so much of the tutorial will work in either an interactive IPython session or a Jupyter notebook session. ![]() ![]() It has a host of useful features, but in this article I will only be talking about one feature (magics) and specifically one of those magics ( %autoreload). It does a good job of explaining why using IPython is superior to the default Python interpreter. What’s so special about %autoreload and why does it often make development faster and simpler? Why IPython and Jupyter?īefore going further, if you haven’t yet used both IPython and Jupyter, check out the ipython interactive tutorial first. One of the main reasons I like these environments is the %autoreload magic. I try to do all of my interactive Python development with either Jupyter notebooks or an IPython session.
0 Comments
Leave a Reply. |