[IPython-User] Python code in a markdown cell
Fri Apr 13 13:56:31 CDT 2012
This makes sense. Since the Markdown is rendered on demand by the browser
it needs to be regenerated when a file is loaded, but since the python code
will not be executed there will likely be errors accessing the non-existent
python objects. So the only way to put python results into Markdown text
is to copy and paste unless there were a feature to perform a one time
evaluation of a python statement in Markdown and replace with a static
result. This kind of feature would certainly cause more problems than its
Is there a concise way to have IPython display the result of an assignment
automatically. For example if in a code cell I had:
x = 10
y = 5
z = x + y
z # alternatively
Is there any way to do this on a single line?
print z = x + y does not work but does IPython have anything magic for this
kind of thing?
On Thu, Apr 12, 2012 at 9:27 PM, Fernando Perez <firstname.lastname@example.org>wrote:
> On Thu, Apr 12, 2012 at 9:11 PM, Fernando Perez <email@example.com>
> > You actually can execute Python code in the kernel, try the following
> > in a markdown cell:
> > IPython.notebook.kernel.execute("x=99");
> > </script>
> > then print x in your next python cell, and you'll see 99 (also note
> > how your prompt counter will have gone up by one).
> BTW, I forgot to note that you should *NOT* put the above tricks into
> any notebook that you actually want to save, because it actually
> breaks reloading of that same notebook later on. As Brian mentioned,
> there are subtle issues with the JS trying to access the IPython
> objects in random places, and in this case having a markdown cell that
> tries to use the IPython object will prevent the file from opening
> cleanly later on (since at web load time, the object isn't fully
> constructed yet).
> IPython-User mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-User