【发布时间】:2020-10-05 15:30:58
【问题描述】:
我在 JupyterLab 中有一个代码,其中包含分布在多个单元格中的多个函数。第一个函数生成一个数据集,该数据集将在其后的所有其他函数中使用。
我要做的是两次运行相同的代码,但修改了其中一个函数。所以它看起来像这样:
data_generating_function() # this function should only be ran once so it generates the same dataset for both trials
function_1() # this is the function that is to be modified once, so there are two version of this function
function_2() # this function and all functions below it stay the same but should be ran twice
function_3()
function_4()
function_5()
所以我会运行一次data_generating_function() 并生成数据集。然后我会运行一个版本的function1() 和它下面的所有函数,然后我会运行另一个版本的function1() 和它下面的所有其他函数。
什么是实现这一点的好方法?我显然可以复制代码并更改一些函数名称,我也可以将它们全部放入一个单元格并创建一个 for 循环。但是,有没有更好的方法可以理想地保留多个单元格?
谢谢
【问题讨论】:
标签: python function jupyter-notebook jupyter-lab