1 | initial version |
I had a similar issue dealing with the preparser so I wrote an IPython extension which adds a cell magic %%noparse
which disables the Sage preparser for the cell its applied to.
Save this code as noparse.py
:
from IPython.core.magic import (Magics, magics_class, cell_magic)
import sage.repl.interpreter
@magics_class
class NoParseMagic(Magics):
@cell_magic
def noparse(self, line, cell):
"""
Use this cell magic to disable Sage preparsing in an IPython cell.
"""
sage.repl.interpreter._do_preparse = False
self.shell.run_cell(cell)
sage.repl.interpreter._do_preparse = True
def load_ipython_extension(ipython):
ipython.register_magics(NoParseMagic)
If you like, you can copy this to .ipython/extensions/
. Then in a Sage Jupyter notebook, you can run:
%load_ext noparse
to load the extension. Now the following works:
%%noparse
type(4)
which yields:
<type 'int'>
instead of:
<type 'sage.rings.integer.Integer'>