解读%load_ext autoreload

对于 IPython版本 3.1, 4.x, and 5.x

%load_ext autoreload
%autoreload 2

然后,您的模块将默认自动重新加载。 这是文档:

File:       ...my/python/path/lib/python2.7/site-packages/IPython/extensions/autoreload.py

Docstring:
``autoreload`` is an IPython extension that reloads modules
automatically before executing the line of code typed.

This makes for example the following workflow possible:

.. sourcecode:: ipython

   In [1]: %load_ext autoreload

   In [2]: %autoreload 2

   In [3]: from foo import some_function

   In [4]: some_function()
   Out[4]: 42

   In [5]: # open foo.py in an editor and change some_function to return 43

   In [6]: some_function()
   Out[6]: 43

The module was reloaded without reloading it explicitly, and the
object imported with ``from foo import ...`` was also updated.

有个窍门:当你在使用 ipython 时忘记了上述所有内容时,试试:

import autoreload
?autoreload
# Then you get all the above

猜你喜欢

转载自blog.csdn.net/weixin_46159962/article/details/127964965
ext
今日推荐