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   ZhangZhihuiAAA  阅读(41)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2023-09-29 Go - Using Log Levels
2023-09-29 Go - Logging to File
2023-09-29 Go - Inspecting Errors
2023-09-29 Go - Wrapping an Error with Other Errors
2023-09-29 Go - Creating Customized Errors
2023-09-29 Go - Using Multiple Versions of the Same Dependent Packages
2023-09-29 Go - Requiring Local Versions of Dependent Packages
 
点击右上角即可分享
微信分享提示