2013-02-07 46 views
2

當我使用python-shell-send-buffer(C-C C-c)時,我可以在python shell中看到我的主緩衝區的更改。如何在Emacs的python-shell-send-buffer上重新加載python模塊?

但是,如果我的緩衝區已導入模塊,他們不會重新加載。它如何被修復?

對於exmple:
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 

回答

0

如果你想這樣做 - 使用ipython。

創建配置 「開發」(或其他):

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配置爲Python-模式,然後設置變量:

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

以此配置啓動的IPython會在重新發送代碼時重新加載模塊。

+0

當我按下'C-c C-p'時,控制檯打開時出現以下錯誤:'IPython profile:dev ^ [[6n^[[JIn [1]:^ [[8D^[[8C'。 也許和'%autoreload 2'有關,'%'符號和'2'的含義是什麼? – Nisba