Request: Enable cell magics inside of .ipy scripts #2539

Closed
rmcgibbo opened this Issue Oct 31, 2012 · 6 comments

Comments

Projects
None yet
4 participants
Contributor

rmcgibbo commented Oct 31, 2012

(Originally opened as #2538, but the code in that PR was a little premature.)

Currently, it's not possible to intersperse regular ipython code with cell magics inside of a .ipy script which is run from the command line via $ipython script.ipy. The problem is that the entire file is processed as a single "cell" and cell magics (the %% literal) are only looked for at the very beginning of a cell, so you can't have any regular python code before the start of the cell magic inside of a .ipy script.

The code in #2538 accomplishes this, but is a bit inelegant. After IPEP2(#2293) and #2447 are merged, this functionality should be relatively straightforward to add.

Contributor

rmcgibbo commented Nov 1, 2012

I just checked out #2447, and the requested functionality works in that branch without modification.

Owner

takluyver commented Nov 1, 2012

I love it when a plan comes together!

Owner

ellisonbg commented Nov 1, 2012

Awesome!

Sent from my iPad

On Nov 1, 2012, at 3:36 AM, Thomas Kluyver notifications@github.com wrote:

I love it when a plan comes together!


Reply to this email directly or view it on GitHub.

takluyver was assigned Feb 11, 2013

Owner

takluyver commented Apr 11, 2013

The fix is now in master.

takluyver closed this Apr 11, 2013

Could somebody give an example of how this works? This fix was merged in 2013, but according to this StackOverflow answer from 2015, it's not possible:

http://stackoverflow.com/a/27951491

Perhaps the answerer was unaware of your change?

Owner

takluyver commented Apr 9, 2015

It may have got broken again. I don't think many people use .ipy scripts, and we don't especially encourage their use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment