如何通过命令行将IPython Notebook转换为Python文件? [英] How do I convert a IPython Notebook into a Python file via commandline?

查看:87
本文介绍了如何通过命令行将IPython Notebook转换为Python文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用 * .ipynb 文件作为事实来源,并以编程方式将它们编译为.py文件以用于预定的作业/任务。

I'm looking at using the *.ipynb files as the source of truth and programmatically 'compiling' them into .py files for scheduled jobs/tasks.

我理解的唯一方法是通过GUI。有没有办法通过命令行来实现?

The only way I understand to do this is via the GUI. Is there a way to do it via command line?

推荐答案

启动笔记本 - 脚本标志将在每次保存时将 .py 文件与 .ipynb 一起保存。
看看 github / ipython / nbconvert ,它目前正在融入IPython本身,所以不要指望文档是准确的,并且nbconvert在没有工作的情况下开箱即用。 (./nbconvert< format>< file.ipynb>)在撰写本文时,< format>在[ python ,latex,markdown,full_html,...])

Start notebook with --script flag will save .py file alongside .ipynb on every save. Have a look at github/ipython/nbconvert which is currently beeing merged into IPython itself, so don't expect the doc to be accurate and nbconvert to work out of the box without working a little. (./nbconvert <format> <file.ipynb>) at time of this writing, <format> in [python, latex, markdown, full_html,...])

你也可以(如ipynb)是json),加载它,循环它和当前命名空间中的 eval codecell。您可以在互联网上找到示例,或者在github上找到IPython wiki。

You can also (as ipynb is json), load it, loop through it and eval codecell in current namespace. You will find example here and there on the internet or IPython wiki on github.

这个答案太旧了,请参阅@williampli的答案。

This answer is too old see @williampli 's answer below.

这篇关于如何通过命令行将IPython Notebook转换为Python文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆