ZhangZhihui's Blog  

 

%reload_ext autoreload
%autoreload 2

以上代码只需执行一次。

对已import的方法做修改,修改的内容直接生效,不需要重新import。

新增的方法需要import才能使用,import之后之前定义的类对象可以使用这个新方法

在一个module中删除一个方法,即使重新import这个module,那个已删除的方法仍然可用。

 

Usage

The following magic commands are provided:

%autoreload%autoreload now

Reload all modules (except those excluded by %aimport) automatically now.

%autoreload 0%autoreload off

Disable automatic reloading.

%autoreload 1%autoreload explicit

Reload all modules imported with %aimport every time before executing the Python code typed.

%autoreload 2%autoreload all

Reload all modules (except those excluded by %aimport) every time before executing the Python code typed.

%autoreload 3%autoreload complete

Same as 2/all, but also adds any new objects in the module. See unit test at IPython/extensions/tests/test_autoreload.py::test_autoload_newly_added_objects

Adding --print or -p to the %autoreload line will print autoreload activity to standard out. --log or -l will do it to the log at INFO level; both can be used simultaneously.

%aimport

List modules which are to be automatically imported or not to be imported.

%aimport foo

Import module ‘foo’ and mark it to be autoreloaded for %autoreload 1

%aimport foo, bar

Import modules ‘foo’, ‘bar’ and mark them to be autoreloaded for %autoreload 1

%aimport -foo

Mark module ‘foo’ to not be autoreloaded.

posted on 2024-09-29 21:27  ZhangZhihuiAAA  阅读(98)  评论(0)    收藏  举报