admin管理员组

文章数量:1332389

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?

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?

Share Improve this question asked Jun 13, 2013 at 15:47 agcontiagconti 18.1k17 gold badges83 silver badges118 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

After talking with the IPython dev team minrk found an answer:

%%writefile filename.py

will write everything below it in the cell to filename.py. link to the converastion.

本文标签: javascriptSave by cell and not by lineIPython save magic Is there a wayStack Overflow