[IPython-dev] what goes wrong with %%file

MinRK benjaminrk at gmail.com
Sun May 12 11:04:15 EDT 2013


On Sun, May 12, 2013 at 7:51 AM, W. Trevor King <wking at tremily.us> wrote:

> On Sun, May 12, 2013 at 07:36:27AM -0700, Min RK wrote:
> > On May 12, 2013, at 7:23, "W. Trevor King" <wking at tremily.us> wrote:
> > > On Sun, May 12, 2013 at 09:56:57AM -0400, Greg Wilson wrote:
> > >> If I have a file called 'data.txt' on my hard drive, and put:
> > >>
> > >> %%file data.txt
> > >>
> > >> in a cell and then execute it, 'data.txt' is overwritten and the data
> is
> > >> lost.  Everyone (including me, when I'm forgetful) expects this to
> load
> > >> and display the existing file content if the file exists, just like an
> > >> editor would.
> > [snip]
> > > Maybe the current %%file magic should be renamed to %%save-file, and
> > > you're expecting a (currently unimplemented?) %%open-file.
> >
> > it is *not* an editor - if you want to load a file's contents into a
> > cell, that's precisely what %load does.
>
> Ah, thanks.  I didn't see anything load-related in the cell magics
> list [1],


That would be because it doesn't make any sense for load to be a cell magic
- cell magics always take the body of a cell as an argument.


> and I couldn't even find a standard-magic list in the docs
> :p [2].  I wasn't proposing an editor-like command, I was saying that
> the ambiguity Greg points out with `%%file` is understandable.  In the
> “explicit is better than implicit” spirit, it would make sense to use
> a more explicit name for a file-saving magic.  On the other hand,
> backwards compatibility has a good deal of weight too.
>

%lsmagic lists magics, as will %lsmagic, etc.

Also, in master if you call `%%file filename` with no cell body, you will
get an error saying "%%file is a cell magic, but the cell body is empty",
so I would consider this part of the issue addressed.


>
> Cheers,
> Trevor
>
> [1]:
> http://ipython.org/ipython-doc/dev/whatsnew/version0.13.html#cell-magics
> [2]: I suppose auto-completion makes such a listing less important.
>
> --
> This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
> For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20130512/19855533/attachment.html>


More information about the IPython-dev mailing list