我正在考虑使用 * .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文件?
发布评论