Python jupyter将参数神奇地传递到笔记本
当您在第一个jupyter笔记本(first.ipynb)中时,您可以执行第二个jupyter笔记本,但是如何传递参数呢 假设第二个具有以下内容:Python jupyter将参数神奇地传递到笔记本,python,jupyter-notebook,Python,Jupyter Notebook,当您在第一个jupyter笔记本(first.ipynb)中时,您可以执行第二个jupyter笔记本,但是如何传递参数呢 假设第二个具有以下内容: xx = 10 您可以从第一个调用第二个,如下所示: %run second.ipynb xx # will print 10 (= nicely set up from the second one) 但是如何将参数传递给第二个笔记本/run magic? 即 然后有一个: if foo is not None: xx = foo
xx = 10
您可以从第一个调用第二个,如下所示:
%run second.ipynb
xx # will print 10 (= nicely set up from the second one)
但是如何将参数传递给第二个笔记本/run magic?
即
然后有一个:
if foo is not None:
xx = foo
在第二个
这种天真的方法在以下方面失败:
NameError: name 'foo' is not defined
i、 e.参数没有传递。因为它在同一进程中执行-我可以在第一个笔记本中将参数定义为变量 它摸起来很脏,但很方便
NameError: name 'foo' is not defined