如何通过命令行将IPython Notebook转换为Python文件?

编程入门 行业动态 更新时间:2024-10-19 02:14:45
本文介绍了如何通过命令行将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文件?

本文发布于:2023-07-27 00:06:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219142.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   命令   文件   Notebook   IPython

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!