You are viewing an older version (9.10.0). Go to latest (9.13.0)
{ } Raw JSON

bundles / IPython 9.10.0 / IPython / core / hooks

module

IPython.core.hooks

source: /IPython/core/hooks.py :0

Members

Summary

Hooks for IPython.

Extended Summary

In Python, it is possible to overwrite any method of any object if you really want to. But IPython exposes a few 'hooks', methods which are designed to be overwritten by users for customization purposes. This module defines the default versions of all such hooks, which get used by IPython if not overridden by the user.

Hooks are simple functions, but they should be declared with self as their first argument, because when activated they are registered into IPython as instance methods. The self argument will be the IPython running instance itself, so hooks have full access to the entire IPython object.

If you wish to define a new hook and activate it, you can make an extension or a startup script <startup_files>. For example, you could use a startup file like this

import os

def calljed(self,filename, linenum):
    "My editor hook calls the jed editor directly."
    print("Calling my own editor, jed ...")
    if os.system('jed +%d %s' % (linenum,filename)) != 0:
        raise TryNext()

def load_ipython_extension(ip):
    ip.set_hook('editor', calljed)

Additional content

Hooks for IPython.

In Python, it is possible to overwrite any method of any object if you really want to. But IPython exposes a few 'hooks', methods which are designed to be overwritten by users for customization purposes. This module defines the default versions of all such hooks, which get used by IPython if not overridden by the user.

Hooks are simple functions, but they should be declared with self as their first argument, because when activated they are registered into IPython as instance methods. The self argument will be the IPython running instance itself, so hooks have full access to the entire IPython object.

If you wish to define a new hook and activate it, you can make an extension or a startup script <startup_files>. For example, you could use a startup file like this

import os

def calljed(self,filename, linenum):
    "My editor hook calls the jed editor directly."
    print("Calling my own editor, jed ...")
    if os.system('jed +%d %s' % (linenum,filename)) != 0:
        raise TryNext()

def load_ipython_extension(ip):
    ip.set_hook('editor', calljed)

Aliases

  • IPython.core.hooks

Referenced by