【问题标题】:How to embed a file excerpt in Jupyter如何在 Jupyter 中嵌入文件摘录
【发布时间】:2018-12-12 13:25:47
【问题描述】:

我想在 Jupyter 的 Markdown 单元中公开我的部分代码。代码位于外部文件中。具体来说,我正在寻找类似的东西:

[file.py:240:255] 这将显示 file.py 的第 240 到 255 行。

我想知道如何实现这一点。我想我们可以在 nbconvert 中编写一个脚本,但这种功能可能已经存在。

【问题讨论】:

    标签: jupyter-notebook markdown nbconvert


    【解决方案1】:

    可以使用内置的 jupyter 命令%load

    %load -r 240-255 path/to/file.py
    

    单元格必须处于代码模式才能执行此命令。唯一的问题是,当单元格类型更改为markdown时,代码没有高亮。

    【讨论】:

      猜你喜欢
      • 2018-07-26
      • 2023-03-12
      • 2021-06-21
      • 2020-11-30
      • 2018-04-23
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 1970-01-01
      相关资源
      最近更新 更多