ipython中的模块导入机制

Python REPL中的模块导入机制

  • How does importing in Python work?

Turns out that, for efficiency reasons, when you import a module in an interactive Python session, Python interpreter does two steps:

  1. First, it checks if the module is already cached in the sys.module
    dictionary.

  2. And only if it’s not there, it actually imports the
    module

Another one of the magic methods in IPython is related to reloading modules. It’s called %autoreload. It’s not enabled by default, so you have to load it as an extension:

%autoreload 0 - disables the auto-reloading. This is the default setting.
%autoreload 1 - it will only auto-reload modules that were imported using the %aimport function (e.g %aimport my_module). It’s a good option if you want to specifically auto-reload only a selected module.
%autoreload 2 - auto-reload all the modules. Great way to make writing and testing your modules much easier.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值