[IPython-dev] Cell Magic names

MinRK benjaminrk@gmail....
Fri Jun 1 23:52:46 CDT 2012


On Fri, Jun 1, 2012 at 9:07 PM, Brian Granger <ellisonbg@gmail.com> wrote:

> On Fri, Jun 1, 2012 at 8:58 PM, MinRK <benjaminrk@gmail.com> wrote:
> > I was playing with my shebang magic, and I decided to test something
> evil:
> >
> >     @cell_magic('#!')
> >     def shebang(self, line, cell):
> >         """Run a cell via a shell command
>
> Oh, what fun, I love it!  Actually, this is not that crazy considering
> that we already have the `!foo` syntax.  I guess the important
> question is this: are the any constraints on the names of cell magics
> at all?  Will this mess up things somehow?
>
> >         The `%%shebang` line is like the #! line, specifying a program
> > (bash, perl, ruby, etc.)
> >         """
> >         p = Popen(line, stdout=PIPE, stderr=PIPE, stdin=PIPE)
> >         out,err = p.communicate(cell)
> >         print(out, end='')
> >         print(err, file=sys.stderr, end='')
> >
> >
> > Which actually lets me do:
> >
> > %%#! bash
> > for i in 1 2 3; do
> >   echo $i
> > done
> >
> > I presume we don't want that to actually work, right?  Kinda fun, though.
>
> I think there are two questions:
>
> * Will this actually break something?
>

I imagine we want magics to be identifiers, but I guess `%%...<space>` is
sufficiently well defined that there's no technical reason why any unicode
characters should be illegal.

* Is another name for this magic clearer?
>

I was just going to call it `%%shebang`, I think `%%#!` is a few too many
special characters in a row.


>
> Cheers,
>
> Brian
>
> > -MinRK
> >
> > _______________________________________________
> > IPython-dev mailing list
> > IPython-dev@scipy.org
> > http://mail.scipy.org/mailman/listinfo/ipython-dev
> >
>
>
>
> --
> Brian E. Granger
> Cal Poly State University, San Luis Obispo
> bgranger@calpoly.edu and ellisonbg@gmail.com
> _______________________________________________
> IPython-dev mailing list
> IPython-dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-dev/attachments/20120601/16548ff6/attachment.html 


More information about the IPython-dev mailing list