Feature request: Save by cell and not by line #: IPython %save magic #3426

Closed
agconti opened this Issue Jun 13, 2013 · 8 comments

Comments

Projects
None yet
2 participants

agconti commented Jun 13, 2013

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? If not, does anyone else have a need for such a feature?

Owner

minrk commented Jun 13, 2013

The notebook is for editing notebooks - if you want to export a notebook to a Python script, that is already provided by the 'save as .py' facility of the notebook.

agconti commented Jun 13, 2013

I don't want to save the entire notebook. Just certain.py files I've loaded in with %loadpy. You can see a rough example of what I mean here on line 39 in the notebook.

agconti commented Jun 13, 2013

With this kind of feature you would be able to interactively develop and manage your projects from the same place.

Owner

minrk commented Jun 13, 2013

Ah, I thnk get it. So basically you want to open/edit/save whole scripts from the notebook UI? We do plan to add that before too long.

agconti commented Jun 13, 2013

Exactly. Is there any current work on it? I'd like to contribute.

Owner

minrk commented Jun 13, 2013

There was a full-page ACE tested a while ago, and something similar will probably come in, but it will have to be done after IPEP 16.

Owner

minrk commented Jun 13, 2013

For now, the closest equivalent workflow is to load a cell with %load, and then write it again with %%writefile filename.py

agconti commented Jun 13, 2013

Hi @minrk,

%%writefile filename.py works perfectly and saves everything in the cell. How can I update the documentation to reflect this? Thanks a lot for your help!

agconti closed this Jun 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment