现在的位置: 首页 > 综合 > 正文

Autoreload of modules in IPython

2012年11月02日 ⁄ 综合 ⁄ 共 570字 ⁄ 字号 评论关闭

ipython很好用,但是如果在ipython里已经import过的模块修改后需要重新reload就需要这样

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

如果想在ipython每次启时自动加载,步骤如下
it may be necessary to generate one first:
1、运行下面的command用来产生ipython_config.py文件

ipython profile create

2、gedit ~/.ipython/profile_default/ipython_config.py添加:

c.InteractiveShellApp.exec_lines = []
c.InteractiveShellApp.exec_lines.append('%load_ext autoreload')
c.InteractiveShellApp.exec_lines.append('%autoreload 2')

抱歉!评论已关闭.