python - 编写 NBConvert 脚本以输出到多个 HTML 文件

标签 python html ipython

我有一个 Python/Pandas 脚本,可以生成一些我想要的报告。目前,NBConvert 始终将文件保存为我的 iPython 笔记本的标题。理想情况下,如果我的报告是关于汽车主题的,我想要一份 [Ferrari、Ford、Tesla,...] 报告,每个报告都保存在各自的公司名称下 [Ferrari.html、Ford.html、Tesla.html,...] 。重要的是,这都是从一个笔记本“Car_Data.ipynb”创建的。

我已阅读此处的文档:NBConvert Documentation

这说明:“nbconvert 创建的输出文件将具有与笔记本相同的基本名称,并将放置在当前工作目录中。”

有谁知道如何从 iPython 笔记本编写此类 HTML 输出的脚本。

目前,我已经实现了下面的代码,它将当前笔记本保存在当前文件名下:

#This is a script sourced from: http://stackoverflow.com/questions/19067822/save-ipython-notebook-as-script-programmatically to save our notebook as HTML
try :
    if(__IPYTHON__) :
        !ipython nbconvert --to html Cluster_Availability_Charts.ipynb;
except NameError :
    pass

感谢您的帮助!

最佳答案

以下是如何插入您自己的文件名并使用 iPython + NBConvert 保存笔记本:

#This is a script sourced from: http://stackoverflow.com/questions/19067822/save-ipython-notebook-as-script-programmatically to save our notebook as HTML
prefix = u'ipython nbconvert --to html --output ' #Trailing space needed
mystr = u'filename_without_html ' #Trailing space needed
suffix = u'My_Notebook.ipynb'
total = prefix + mystr + suffix
print total
try :
    if(__IPYTHON__) :
        get_ipython().system(total)
except NameError :
    pass

关于python - 编写 NBConvert 脚本以输出到多个 HTML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26105705/

相关文章:

html - 任何地方的通用 CSS 模板(不是布局)?

python - 使用 ipywidgets 的交互式 matplotlib

Python - 回文函数 : Receiving error "list indices must be integers or slices, not str"

Python随机改变数据类型

python - 在 PyQt 中避免崩溃/挂起的良好做法是什么?

python - 使用 python 将多个文件中的数据加载到单个变量中

python - 更改 python 解释器窗口

python - 带有 argparse 的 Python 中的可选标准输入

ios - 奇怪的亮点 Mobile Safari

html - 如何实现jsp浏览器 Action