我想将我的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