[英]How do I get IPython autoreload magic to load automatcially when using an embedded shell?
我的ipython_config.py
包含以下ipython_config.py
:
print "Test autoreload" #confirm this gets loaded
c = get_config()
c.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = ['%autoreload 2']
它似乎適用於普通的ipython會話:
$ ipython
Test autoreload
In [1]: %autoreload 2
In [2]:
但是,當使用使用IPython.embed()的嵌入式Shell腳本時,自動重裝魔術不再起作用。
例如,在shell.py
:
from IPython import embed
embed()
這仍然加載我的ipython_config.py,如打印"Test autoreload"
所證明的那樣,但是autoreload擴展未加載(沒有%autoreload魔術):
$ python shell.py
Test autoreload
In [1]: %autoreload 2
ERROR: Line magic function `%autoreload` not found.
代替
from IPython import embed
embed()
用這個
from IPython.frontend.terminal.ipapp import TerminalIPythonApp
app = TerminalIPythonApp.instance()
app.initialize(argv=[])
app.start()
您可以運行python shell.py
In [1]: %autoreload 2
In [2]:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.