4

I'm creating a Django tutorial in an IPython Notebook and I want to use the %save magic to save .py files to create / edit / advance a website as the tutorial progresses. The problem is the %save magic works by specifying which lines to save. Undoubtedly, the line number will change when users execute the cells before the file out of order or multiple times.

I'd like to work like this:

some .py file imported into the notebook.
# do all sorts of website things
%save -f this.py file

where it would save the contents of the cell without needing the line number. Is there any way to do this with the existing functionality of the %save magic?

4

1 回答 1

10

在与 IPython 开发团队交谈后,minrk 找到了答案:

%%writefile filename.py

将在单元格中将其下方的所有内容写入filename.py. 链接到对话

于 2013-06-13T22:05:53.860 回答