![]() ![]() 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. List contains sys, _main_, and _builtin_, to prevent, e.g.I try to do all of my interactive Python development with either Jupyter notebooks or an IPython session. Takes a list of modules to exclude from reloading. Recursively reload all modules used in the given module. deep_import_hook ( name, globals=None, locals=None, fromlist=None, level=-1 ) ¶ Handle ‘from module import a, b, c’ imports. ensure_fromlist ( mod, fromlist, buf, recursive ) ¶ add_submodule ( mod, submod, fullname, subname ) ¶ import_submodule ( mod, subname, fullname ) ¶. load_next ( mod, altmod, name, buf ) ¶Īltmod is either None or same as mod. If globals doesn’t come from a package or a module in a package, or aĬorresponding entry is not found in sys.modules, None is returned. The package’s entry in sys.modules is returned. If globals is from a package’s _init_.py, If globals comesįrom the module (not itself a package), this returns the Return the package that an import is being performed in. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |