[IPython-dev] Cell Magic names
Brian Granger
ellisonbg at gmail.com
Sat Jun 2 00:07:32 EDT 2012
On Fri, Jun 1, 2012 at 8:58 PM, MinRK <benjaminrk at 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?
* Is another name for this magic clearer?
Cheers,
Brian
> -MinRK
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
--
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger at calpoly.edu and ellisonbg at gmail.com
More information about the IPython-dev
mailing list