[英]How to %run a list of notebooks in Databricks
I'd like to %run a list of notebooks from another Databricks notebook.我想 %run 来自另一个 Databricks 笔记本的笔记本列表。
my_notebooks = ["./setup", "./do_the_main_thing", "./check_results"]
for notebook in my_notebooks:
%run notebook
This doesn't work ofcourse.这当然行不通。
I don't want to use dbutils.notebook.run()
as this creates new jobs and doesn't return anything back - I want everything executable and queryable from the main notebook.我不想使用dbutils.notebook.run()
因为这会创建新的作业并且不会返回任何东西 - 我希望主笔记本中的所有内容都是可执行和可查询的。
I thought perhaps it might be possible to import the actual module and run the function.我想也许可以导入实际的模块并运行 function。
?%run
shows the command points to IPython/core/magics/execution.py and run
is a method of the class ExecutionMagics
in the module execution
. ?%run
显示命令指向 IPython/core/magics/execution.py 并且run
是模块execution
中 class ExecutionMagics
的一个方法。 So perhaps, I could use execution.ExecutionMagic.run()
if I created an instance of the class.所以也许,如果我创建了 class 的实例,我可以使用execution.ExecutionMagic.run()
。
But it's beyond me - tricky and I'm doubting it's an effective solution.但这超出了我的范围 - 棘手而且我怀疑它是否是一个有效的解决方案。
How can this be done?如何才能做到这一点?
Am I really stuck with:-我真的坚持:-
%run./a notebook
%run./another_notebook
%run./yet_another_hardcoded_notebook_name
Eternally grateful for any help!永远感谢任何帮助!
Unfortunately it's not possible to do - %run
doesn't allow to pass notebook name as a variable (see this answer with more details, and possible workaround).不幸的是,这是不可能的 - %run
不允许将笔记本名称作为变量传递(有关更多详细信息和可能的解决方法,请参阅此答案)。
Another approach would be to use so-called arbitrary files in repos functionality - if you define code as a Python file instead of notebook, then you'll be able to use it as normal Python module, and even load it dynamically if you need.另一种方法是在 repos 功能中使用所谓的任意文件- 如果您将代码定义为 Python 文件而不是笔记本,那么您将能够将其用作正常的 Python 模块,甚至可以在需要时动态加载它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.