[IPython-dev] Using argparse for %magics

Fernando Perez fperez.net@gmail....
Tue Apr 7 13:11:53 CDT 2009

On Sun, Apr 5, 2009 at 1:50 AM, Robert Kern <robert.kern@gmail.com> wrote:
> I have updated my personal collection of %magics today:
>   http://www.enthought.com/~rkern/cgi-bin/hgwebdir.cgi/kernmagic
> Not all of them are aimed at inclusion into IPython proper, but I think most of
> them would be useful as Extensions, at least. Here are all of the collected
> docstrings:
> http://www.enthought.com/~rkern/cgi-bin/hgwebdir.cgi/kernmagic/raw-file/tip/help.txt
> The recently added magics are
>   %push_err/%pop_err for controlling numpy's error handling options via a
> stack. These complement %push_print/%pop_print, which control numpy's printing
> options the same way.
>   %print_methods (optional alias %pm) for printing the methods of an object,
> grouped by the defining class.
>   %print_traits (optional alias %pt) for printing the traits of a HasTraits
> object, grouped by the defining class. Crazy-useful.
> One thing you might want to consider for IPython proper is the mini-framework I
> use for parsing the arguments. I made some decorators which use argparse (now in
> IPython.externals, amen) to build parsers for those magics that take CLI-style
> --options. It's nicely declarative and makes the option parsing and help text
> style uniform across all of the magics. We've discussed having a standard for
> all of the --option-taking %magics that come with IPython, and I put this
> forward as an improvement over the current manual getopt code.

Just an initial reply before we dive into this, since I'm going
semi-offline for a couple of days.

+1 to argparse for this, as long as we carry it (not as a separate
dependency).  I've been thinking about cleaning up the magics as part
of the core reorg Brian will work on soon, and this would fit nicely
into that idea.



More information about the IPython-dev mailing list