python - 修改单元格的元数据

标签 python jupyter-notebook metadata

我想以某种方式将我的 IPython.html.widgets 的值存储在我的 ipython 笔记本中。

有没有办法从单元格本身的代码修改当前单元格的元数据?

最佳答案

我不知道如何在笔记本中执行此操作,但我找到了一种使用自定义 preprocessor 来执行此操作的方法和 nbconvert。

您可以创建一个扩展 nbconvert.preprocessors.ExecutePreprocessor 的类。在 preprocess(或 preprocess_cell)方法中,添加用于将相关输出存储在单元元数据中的逻辑。

类似于:

class MyExecutePreprocessor(ExecutePreprocessor):
    def preprocess_cell(self, cell, resources, index):
        # Execute the cell normally
        cell, resources = super().preprocess_cell(cell, resources, index)
        # Add your magic here
        cell.metadata['widgets'] = {'stuff':'that is cool'}
        return cell, resources

然后您可以执行此预处理器 programatically ,或作为 nbconvert 的参数.

关于python - 修改单元格的元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23917036/

相关文章:

python - 在 Jupyter Notebook 中使用 watson_developer_cloud 时出现错误

android - Flutter AndroidManifest 错误

python - 具有 ManyToMany 字段的模型方法

python - Masonite - AttributeError > 'str' 对象没有属性 'filename'

python - TensorFlow - 从 TensorBoard TFEvent 文件中导入数据?

app-store - 如何使用FaSTLane/Deliver更新有关贸易代表联系信息的元数据?

python - 如何使用 python 从图像中提取元数据?

python - 使用 for 循环 Python 为数组赋值

python - IPython 笔记本 : code reuse

java - 使用 py4j 将 Log4j 连接到 java/python 项目中的 ipython 笔记本 stderr