【发布时间】:2018-03-07 16:43:24
【问题描述】:
我正在尝试执行我在命令行上编写的名为RemoveCellsWithNoTags 的自定义预处理器。在documentation 之后,这是我尝试的命令
jupyter nbconvert --Exporter.preprocessors=["custompreprocessor.RemoveCellsWithNoTags"] --to script mynotebook.ipynb
这给了我以下错误
zsh: no matches found: --Exporter.preprocessors=[custompreprocessor.RemoveCellsWithNoTags]
标准命令可以正常工作
jupyter nbconvert --to script mynotebook.ipynb
为了完整起见,这里是我的custompreprocessor.py 文件中的代码。
from nbconvert.preprocessors import Preprocessor
class RemoveCellsWithNoTags(Preprocessor):
def preprocess(self, notebook, resources):
notebook.cells = [cell for cell in notebook.cells if 'tags' in cell.metadata]
return notebook, resources
更新 #1 - 使用配置文件的解决方法
我已经设法使用配置文件来解决这个问题,虽然这对我来说并不理想,但它正在工作。
nb_convert_config.py文件内容
c = get_config()
c.NbConvertApp.notebooks = ['mynotebook.ipynb']
c.NbConvertApp.export_format = 'python'
c.Exporter.preprocessors = ['custompreprocessor.RemoveCellsWithNoTags']
然后命令变成
jupyter nbconvert --config nbconvert_config.py
【问题讨论】:
标签: jupyter-notebook jupyter nbconvert