ignore markdown cells in `jupyter nbconvert` with `--to script`

女生的网名这么多〃 提交于 2019-12-20 04:22:54

问题


Is it possible to have jupyter nbconvert ... --to script ignore markdown cells rather than convert them to comments?

I'm asking because I want to use flake8 to check the Python code that's generated but I don't want to include the markdown cells (for example, because they are often long lines, and I don't want flake8 to complain about them).


回答1:


There is the command line argument PythonExporter.exclude_markdown that does what you want. To get a list of pep8 errors that just look at the code cells, I run

jupyter nbconvert my_notebook.ipynb --stdout --to python --PythonExporter.exclude_markdown=True | flake8 - --ignore=W391



回答2:


This seems to work:

Create a template strip_markdown.tpl

## remove markdown cells
{% extends 'python.tpl'%}
{% block markdowncell -%}
{% endblock markdowncell %}

jupyter nbconvert my_notebook.ipynb --to python --template=strip_markdown.tpl



来源:https://stackoverflow.com/questions/37423380/ignore-markdown-cells-in-jupyter-nbconvert-with-to-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!