简体   繁体   English

Jupyter Notebook - 运行单元格并另存为 .py 文件

[英]Jupyter Notebook - run cell and save as .py file

I know of the %%writefile .py cell-magic command but it causes the cell to not run.我知道%%writefile .py cell-magic 命令,但它会导致单元无法运行。 What I want is for the cell to run and create the .py as well.我想要的是让单元格运行并创建 .py 。

Edit 1: I only want the original code in the cell to be saved as a .py file.编辑 1:我只想将单元格中的原始代码另存为 .py 文件。 I don't need the results我不需要结果

I would try to:我会尝试:

  1. Use the %%writefile magic in the next cell, referencing the last one在下一个单元格中使用%%writefile魔法,引用最后一个

or或者

  1. Use the %save line magic instead.改用%save行魔法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM