[IPython-dev] Minus signs in argparse line magics

MinRK benjaminrk at gmail.com
Fri Aug 10 19:04:37 EDT 2012

On Fri, Aug 10, 2012 at 3:49 PM, Matthew Brett <matthew.brett at gmail.com>wrote:

> Hi,
> On Fri, Aug 10, 2012 at 5:39 PM, MinRK <benjaminrk at gmail.com> wrote:
> > You can use '--' to halt argument parsing in argparse, so you should be
> able
> > to do:
> >
> > %R -- c(1, -1)
> Yes, indeed - that was in my original mail as a workaround, but
> understanding why that's a good idea requires understanding that the
> whole line is being option parsed, and so it's a bit heavy on the eye,
> and I found I was preferring either to use cell magics or adjust the
> whitespace in the line to avoid the option parsing...
> I think most people would expect the options to follow the magic
> command and be clustered together, but would not expect to consider
> options at any position in the input string.  I don't think there's a
> way to make argparse do that by default...

I don't think that's possible.  This is actually why I have tried to avoid
having options in line magics that also take a blob.  For instance, %px
takes none of the options %%px can take, because I have been burned so many
times by the magics that take python code, such as %timeit getting parsed

The only reasonable approaches I see:

1. line magics that take blobs (e.g. Python code, or R code) should not
take any options (or at least minimal ones that can be parsed simply and
manually from the front or back of the argstring)
2. *always* use an explicit delimiter for line magics that separates flags
from the blob.

2. is really identical to cell magics, where the delimiter is a newline.

With the advent of cell magics, I am inclined to remove as many options as
we can from line magics that take code.

> Cheers,
> Matthew
> _______________________________________________
> 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/20120810/b13469dd/attachment.html>

More information about the IPython-dev mailing list