The Sage Input Hook - The Sage Command Line

Skip to content
Back to top
View this page
Edit this page

# The Sage Input Hook

This lets us perform actions while IPython is sitting at the terminal input prompt. We use it to reload attached files if they have changed.

sage.repl.inputhook.install()

  Install the Sage input hook.

  EXAMPLES:

  Make sure ipython is running so we really test this function:

  Sage

      sage: from sage.repl.interpreter import get_test_shell
      sage: get_test_shell()
      <sage.repl.interpreter.SageTestShell object at ...>

  Python

      >>> from sage.all import *
      >>> from sage.repl.interpreter import get_test_shell
      >>> get_test_shell()
      <sage.repl.interpreter.SageTestShell object at ...>

  Run the function twice, to check it is idempotent (see Issue #35235):

  Sage

      sage: from sage.repl.inputhook import install
      sage: install()
      sage: install()

  [Python]

      >>> from sage.all import *
      >>> from sage.repl.inputhook import install
      >>> install()
      >>> install()

sage.repl.inputhook.sage_inputhook(context)

sage.repl.inputhook.uninstall()

  Uninstall the Sage input hook.

  EXAMPLES:

  Sage

      sage: from sage.repl.inputhook import uninstall
      sage: uninstall()

  Python

      >>> from sage.all import *
      >>> from sage.repl.inputhook import uninstall
      >>> uninstall()