如何在Emacs中的python-shell-send-buffer上重新加载python模块?

时间:2013-02-07 20:16:57

标签: python emacs

当我使用python-shell-send-buffer(C-c C-c)时,我可以看到python shell中主缓冲区的变化。

但是如果我的缓冲区导入了模块,则不会重新加载。怎么修好?

例如:
main.py:

from functions import foo
print 'a'

functions.py:

def foo():
    print 'bcdef'

因此,如果我更改foo()并在main.py上运行python-shell-send-buffer,它会在第一时间为我提供相同的foo()

a
bcdef   # never changed

1 个答案:

答案 0 :(得分:0)

如果你想这样做 - 使用ipython。

创建配置" dev" (或其他):

ipython profile create dev
[ProfileCreate] Generating default config file: u'/home/username/.config/ipython/profile_dev/ipython_config.py'

并将这些行添加到" ipython_config.py":

c.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = ['%autoreload 2']

然后在Emacs config中为python-mode设置变量:

(setq
   python-shell-interpreter "ipython"
   python-shell-interpreter-args "--profile=dev"
)

启动此配置的IPython会在您重新发送代码时重新加载模块。