我想將我的iPython Notebook中的一些單元收集到python腳本中。但是,我無法用「writefile -a」魔法導入已添加到腳本中的函數。這裏有一個4芯筆記本複製的問題:「ImportError:No module named」error after「writefile」
單元1:保存功能分爲foo.py
%%writefile foo.py
def some_func():
print 42
小區2:使用函數從foo.py
from foo import some_func
some_func()
這版畫42成功。
細胞3:添加其他功能foo.py改爲
%%writefile foo.py -a
def other_func():
print 43
細胞4:嘗試導入other_func
from foo import other_func
other_func()
ImportError: cannot import name other_func