从另一个笔记本运行Jupyter笔记本 [英] Running a Jupyter notebook from another notebook

查看:109
本文介绍了从另一个笔记本运行Jupyter笔记本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能从另一个* .ipynb文件运行* .ipynb文件并获得返回值. 我知道我们可以这样运行:

I wonder if it is possible to run a *.ipynb file from another *.ipynb file and get a returned value. I know that we can run like this:

%run ./called_notebook.ipynb

被叫笔记本包含:

def foo():
    print(1)
    return 2
foo()

但是它只打印"1",而没有给我机会处理返回的值.可能吗?是否存在以下类型的代码:

But it only prints "1" without giving me the opportunity to handle the returned value. Is it even possible ? Does the following kind of code even exist :

a = %run ./called_notebook.ipynb

?

谢谢!

推荐答案

我建议从新笔记本运行foo函数.换句话说:

I'd suggest running the foo function from the new notebook. In other words:

%run ./called_notebook.ipynb
foo()

我认为,这是使用%run magic命令的最佳实践.将高级API存储在单独的笔记本中(例如foo),但在主笔记本中保持函数调用可见.

In my opinion, this is best practices for using the %run magic command. Store your high level APIs in a separate notebook (such as foo), but keep your function calls visible in the master notebook.

这篇关于从另一个笔记本运行Jupyter笔记本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆